Wednesday, 9 January 2013

How can we read xml file in php

<div dir="ltr" style="text-align: left;" trbidi="on">
function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
}

$rssdetail=get_url_contents('http://feeds.feedburner.com/KevinMd-MedicalWeblog');
$rss=simplexml_load_string($rssdetail);
foreach($rss-&gt;children() as $item)
{

 for($i=0;$i&lt;=5;$i++)
{
   $sub_title = $item-&gt;item[$i]-&gt;title;
  $description = $item-&gt;item[$i]-&gt;description;
  $link = $item-&gt;item[$i]-&gt;link;
  $pubDate = $item-&gt;item[$i]-&gt;pubDate;
}
}
</div>

Friday, 7 December 2012

How to generate excel in php

How to Generate Excel in php, its so much simple, so dont be frustrate. Just see below.

<?php
include('PHPExcel.php');

$worksheet=new PHPExcel();

$worksheet->getProperties()->setCreator("Maarten Balliauw")

        ->setLastModifiedBy("Maarten Balliauw")

        ->setTitle("Office 2007 XLSX Test Document")

        ->setSubject("Office 2007 XLSX Test Document")

        ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")

        ->setKeywords("office 2007 openxml php")

        ->setCategory("Test result file");
      
        /* Set the cells values */
      
        $i=1;
             $worksheet->setActiveSheetIndex(0)

                                           ->setCellValue('A'.$i,"Sr no.")

           ->setCellValue('B'.$i,"Date")
        
           ->setCellValue('C'.$i,"Sales")
        
           ->setCellValue('D'.$i,"Partners")
        
           ->setCellValue('E'.$i,"Refund")
        
           ->setCellValue('F'.$i,"Net Sales")
        
           ->setCellValue('G'.$i,"Sales")
        
           ->setCellValue('H'.$i,"Eps")
        
           ->setCellValue('I'.$i,"%Q")
        
           ->setCellValue('J'.$i,"%R")
        
           ->setCellValue('K'.$i,"%TTL")
        
           ->setCellValue('L'.$i,"Reg")
        
           ->setCellValue('M'.$i,"Epr")
        
           ->setCellValue('N'.$i,"%Q")
        
           ->setCellValue('O'.$i,"%TTL")
        
           ->setCellValue('P'.$i,"Qual")
        
           ->setCellValue('Q'.$i,"Epq")
        
           ->setCellValue('R'.$i,"%Q")
           ->setCellValue('S'.$i,"Not Qual")
        
           ->setCellValue('T'.$i,"%TTL")
        
           ->setCellValue('U'.$i,"TTL");
         
         
         
header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment;filename="dailySales.xls"');

header('Cache-Control: max-age=0');



$objWriter = PHPExcel_IOFactory::createWriter($worksheet, 'Excel5');

$objWriter->save('php://output');

exit;

?>        


You can download link the Code from this link(Download)

Wednesday, 21 November 2012

Create Stored Procedure With Php Mysql

Here we will discus, how to use procedure with mysql and php.


Procedure is so much beneficial for  long join query, it will save the time when you load your page.procedures are same as functions .

=>firstly we Create  simple stored procedure into our database

create PROCEDURE testProc()
begin
select field1 from table;
end ;


=>Now we can use the testProc procedure into our php code

<?php $rs=mysql_query('call testProc()'); ?>


Note:Remeber one thing that after using procedure your database connection will automatically closed.

=>Now we will create parameterize procedure into our database

CREATE PROCEDURE  get_users(IN var1 INT,OUT var2 VARCHAR(100),OUT var3 VARCHAR(100))
BEGIN
SELECT first_name, last_name
INTO var2, var3
FROM users
WHERE users_id = var1;
END


=>Now we can use the get_users procedure into our php code
<?php
$rs = mysql_query( ‘CALL get_user(1, @first, @last)’ );
$rs = mysql_query( ‘SELECT @first, @last’ );
while($row = mysql_fetch_assoc($rs))
{
var_dump($row);
}

?>


Note: Customize this code according to your requirement

Tuesday, 20 November 2012

How to call ajax with javascript

How to call ajax with javascript
   its so simple just call javascript function onclick or onchange or onblur or onhover,
   on which event you want to call the function its depend on you.
  
 create  callajax.php
  

  <html>
  <head>


 <script>
 
  function callajax()
  {
  stateval=document.getElementById('state').value;
  if(Window.XMLHTTP)
  {
  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
  }
  else
  {
  xmlhttp=new XMLHttpRequest();
  }
  xmlhttp.onreadystatechange=function(){
 if(xmlhttp.readyState==4 && xmlhttp.status==200)
 {
 document.getElementById('citytd').innerHTML=xmlhttp.responseText;
 }
  }
  xmlhttp.open('GET','ajax.php?state_id='+stateval,true);
  xmlhttp.send()
  }
  </script>
  </head>
  <body>
  <table>
  <tr>
  <td>name</td><td><select name="state" id="state" onchange="callajax()">
  <option>select state</option>
  <option value="1" >Alaska</option>
  <option value="2" >Alabama</option>
  <option value="3" >California</option>
  <option value="4" >Florida</option>
  </select>
  </td></tr>
<tr> <td>address</td><td id="citytd"><select name="city" id="city"><option>Select City from here</option></select></td>
  </tr>
 
  </table>
 
  </body>
  </html>
 
 
  Now below code is ajax.php, where you will execute your code and display on call ajax.php
 
  ajax.php
 
  <!-- write you code here, you can use the $_GET['state_id'] and select the data of city from database -->
<!-- here i am typing only static content -->
<select><option>apol</option><option>ajax</option></select>



Note: You can customize your code according to your requirement