QUOTE(Maris Diana @ 10 May, 2008 - 06:39 AM)

Hello! I am a beginner in PhP and I would like to know how to import data from Excel files into a MySQL database by using PhP and also export data from the database into Excel or Pdf files. Need help fast! Thank you!
Hey,
The best way for you to do that would be to export the Excel file in a plain text delimited format. A good format to use would be tab delimited. This will place a tab between each item in the database. For instance:
John Doe 123 Main Street Anytown, USA
Which is actually the same as
John\tDoe\t123 Main Street\tAnytown, USA
You could then write a function that opens the text file generated, explodes() it on the tabs "\t", and loops through each row and inserts it into the database. I actually just did this at my job to help get a student database into Excel.
The reverse holds true when you're going the opposite way. You would want to loop through each row of your database, fwrite() them to a file, and separate each column by a tab.
CODE
$file = fopen("yourfile.txt", 'w');
$sql = "select * from users";
$result = mysql_query($sql) or die ( mysql_error() );
$fileString = ""
while ($row = mysql_fetch_array($result) ) {
$fileString = $row['username'] . "\t" . $row['password'] . "\t" . $row['firstname'] . "\n";
}
fwrite($file, $fileString);
fclose($file);
That would loop through a table named users, and output each field into a row. There are more elegant ways to do it, but that should at least give you the general concept. You could then import that file as a tab delimited file in Excel.
Hope that helps! I know it was a mouthful.
Andrew