 |
|
 |
Main Menu |
|
 |
Forums |
|
 |
Programming Contest |
|
 |
Documentation
|
|
 |
Partner
Sites |
|
 |
Sponsors |
|
 |
|
|
Register •
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 1 post ] |
|
Author |
Message |
futhon
Junior Member
Joined: Wed Nov 11, 2009 8:31 pm Posts: 26
|
 sql to excel
Hi, I am trying to save my sql results into an excel file. I managed to found a script from google search. It works perfectly well if my results are all allocate in one single table. However, i am using joined-table to show my results. Can anyone guide me along how am i suppose to solve this problem? Million thanks to you... this is the original script: [PHP]while($row = mysql_fetch_row($results)){ $line = ''; foreach($row as $value){ if(!isset($value) || $value == ""){ $value = "\t"; }else{ # important to escape any quotes to preserve them in the data. $value = str_replace('"', '""', $value); # needed to encapsulate data in quotes because some data might be multi line. # the good news is that numbers remain numbers in Excel even though quoted. $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); # Nice to let someone know that the search came up empty. # Otherwise only the column name headers will be output to Excel. if ($data == "") { $data = "\nno matching records found\n"; } # This line will stream the file to the user rather than spray it across the screen header("Content-type: application/octet-stream"); # replace excelfile.xls with whatever you want the filename to default to header("Content-Disposition: attachment; filename=excelfile.xls"); header("Pragma: no-cache"); header("Expires: 0"); [/PHP] this is mine using join table: [PHP]while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) { $device_num = $row['device_num']; $device_rev = $row['device_rev']; $device_site = $row['device_site']; $device_platform = $row['device_platform']; $device_dibid = $row['device_dibid']; $device_designid = $row['device_designid']; $socketnum = $row['socket_idnum']; $fedexnum = $row['fedex_num']; $subcon_name = $row['subcon_name']; //$subconsite = $row['subcon_site']; $device_socketID = $row['device_socketID']; $device_subconID = $row['device_subconID']; $device_tpe = $row['device_tpe']; $device_remark = $row['device_remark']; $date = $row['date']; /* for this part, i retrieve the result from the respective table into the main table */ $query_rev = "SELECT rev_label FROM rev WHERE rev_id = '$device_rev' "; $results_rev = mysql_query($query_rev) or die (mysql_error()); $row_rev = mysql_fetch_array ($results_rev); //extract ($row_rev); $rev_label = $row_rev['rev_label']; ..... /* for this part, the retrieved result from the respective table into the main table */ <tr> <td bgcolor="#ffffff" width="10%"> <?php echo $device_num ; ?> </td> <td bgcolor="#ffffff" width="2%"> <?php echo $rev_label ; ?> </td>[/PHP]
|
Tue Dec 29, 2009 2:46 am |
|
 |
|
|
Page 1 of 1
|
[ 1 post ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|
|