Evanthes Posted August 16, 2006 Share Posted August 16, 2006 I am running a program that queries the database, based on user input. Now i want to be able to backup specific searches to a excel file. All the Mysql queries are working dandy, and Ive followed the tutorial on the website to export to Excel but i must be missing somehting because everything (the columns and the data) is just printing into one cell. So I know I'm close to getting this to work seeing how my data is getting passed to the file but i guess my problem lies with the formatting. Does anyone know what the problem might be? Could it be something with my database? I'll post the code from the tutorial for reference. [code=php:0]include('include.php'); // includes mysql connection// creating variable names$searchterm=$HTTP_GET_VARS['searchterm']; // begin here with code to push data to PDF/EXCEL $select = "select * from data.tbl_sites where zone = '".$searchterm."'" ; $export = mysql_query($select); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t";}while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n";}$data = str_replace("\r","",$data);if ($data == "") { $data = "\n(0) Records Found!\n"; } header("Content-type: application/x-msdownload");header("Content-Disposition: attachment; filename=extraction.xls");header("Pragma: no-cache");header("Expires: 0");print "$header\n$data"; ?>[/code]thanks for the help guys I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/17741-mysql-excel/ Share on other sites More sharing options...
Ninjakreborn Posted August 16, 2006 Share Posted August 16, 2006 why not database it, or flat file it in a txt file, outside the server. I see people using excel but don't understand hte significance. Quote Link to comment https://forums.phpfreaks.com/topic/17741-mysql-excel/#findComment-75757 Share on other sites More sharing options...
Evanthes Posted August 16, 2006 Author Share Posted August 16, 2006 cause boss said thats what he wants :D Quote Link to comment https://forums.phpfreaks.com/topic/17741-mysql-excel/#findComment-75798 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.