5 Replies - 9910 Views - Last Post: 20 January 2009 - 10:46 AM Rate Topic: -----

#1 shahil09  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 10-January 09

how to Export data in Excel Format from data base in php script

Posted 10 January 2009 - 04:45 AM

i want to know about how to Export data in Excel format from database in php
Is This A Good Question/Topic? 1

Replies To: how to Export data in Excel Format from data base in php script

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: how to Export data in Excel Format from data base in php script

Posted 10 January 2009 - 05:42 AM

I would save it to a text file as CSV, then let Excel import it.
Was This Post Helpful? 0
  • +
  • -

#3 doctrinedhey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-January 09

Re: how to Export data in Excel Format from data base in php script

Posted 20 January 2009 - 01:13 AM

i found something about excel using php..



try this link..

http://www.ustrem.or...ls-with-php-en/



hope this help...

This post has been edited by doctrinedhey: 20 January 2009 - 01:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 indrampk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-January 09

Re: how to Export data in Excel Format from data base in php script

Posted 20 January 2009 - 01:59 AM

database there is a option export you cn use that it default save datain the database in excel i think. If u know that and want php code

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
Was This Post Helpful? 0
  • +
  • -

#5 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: how to Export data in Excel Format from data base in php script

Posted 20 January 2009 - 02:10 AM

simply echo out the data from your database in php, then copy into an empty csv document. e.g.

MySQL data:
--------------
userId, userName
	1	Pete 
	4	Dave



then in PHP:

<?php
//connect to db
$sql = mysql_query('SELECT * FROM tbluser');
while($row=mysql_fetch_assoc($sql)){
echo $row['userId'].','.$row['userName'].'<br/>';
}
?>



Which will print something like so to the browser:

1,Pete
4,Dave

Which you copy into an empty csv and load into excel (ensuring row identifier is set to new line)

And there you go! Simple as that :)

This post has been edited by pemcconnell: 20 January 2009 - 02:10 AM

Was This Post Helpful? 0
  • +
  • -

#6 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: how to Export data in Excel Format from data base in php script

Posted 20 January 2009 - 10:46 AM

You could even take it a step further and write each line to a text file with the extension '.csv', and then do a header redirect to that file. That would trigger a download and you can simply save the file to your computer and do what you need to with it.

I believe I've written a tutorial on this exact subject in the PHP Tutorials section of this site. It's mostly what pemcconnell said, but may be worth taking a look at.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1