Monday, 23 July 2012

How To Create excel file with Mysql Data using php Code.


Hi friends, I have code for how to create a excel file with mysql data using php code.
Follow the below steps to retrieve the data from database
Config.php
<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>

a.php

<?php
          include("config.php");
          $filename = "excelwork.xls";
          $exists = file_exists('excelwork.xls');
          if($exists)
          {
                   unlink($filename);
          }
                   $filename = "excelwork.xls";
                   $fp = fopen($filename, "wb");
                   $sql = "select * from product";
                   $result = mysql_query($sql);
                   $schema_insert = "";
                   $schema_insert_rows = "";
                   for ($i = 1; $i < mysql_num_fields($result); $i++)
                   {
                   $insert_rows .= mysql_field_name($result,$i) . "\t";
                   }
                   $insert_rows.="\n";
                   fwrite($fp, $insert_rows);
                   while($row = mysql_fetch_row($result))
                   {
$insert = $row[1]. "\t" .$row[2]. "\t".$row[3]. "\t".$row[4]. "\t".$row[5];
                   $insert .= "\n";               //       serialize($assoc)
                   fwrite($fp, $insert);
                   }
                   if (!is_resource($fp))
                   {
                             echo "cannot open excel file";
                   }
                   echo "success full export";
                   fclose($fp);
?>
This is the steps to create excel file with mysql data using php code.
Once u run a.php it create excelwork file.

3 comments:

Please provide your product table data or structure

So now your strategy is great... you have to begin to figure out how to trust it. After all taekwondo kicks work if the strategy is correct. Furthermore, your kicks will work on the off chance that you let them stream. So discover approaches to make yourself unwind in Dojang. Drop your shoulders when they feel tense. Inhale and shake your legs on the off chance that you get apprehensive. Venture back and grin in the event that you have a craving for fueling a kick into the pack.

On the off chance that you are not used to unwinding it takes work. You need to continue reminding yourself it's OK to give up. Be that as it may, once you begin to believe your taekwondo kicks your outcomes will be fabulous! For more details: itfofindia.com.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More