kirkh34 Posted October 20, 2010 Share Posted October 20, 2010 hello, i have a while loop that displays multiple tables of data depending on how many are in the database... i have a link if you click it will redirect to another page that prompts you to save an xls file with the table data... this was all working for me before when i had the while loop display rows of data in one table...well i decided that i would like the while loop to display a separate table each time... when i changed it... the xls file only shows one table of data... how can i set up so it will export all tables of data... is there some kind of loop i can set up for it to append the tables?? i have the table data all in a variable $table which i put into a hidden form field that redirects to the xls export page.... any help is appreciated... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Admin</title> </head> <body> <?php $sql= mysql_query("SELECT * FROM programs") or die (mysql_error()); while($row = mysql_fetch_array($sql)){ $table = "<table border='1' width='600' style='border-collapse:collapse;'>" . "<th colspan='4'>Programs</th>" . "<tr>" . "<td>ID</td>" . "<td>Views</td>" . "<td>Enabled</td>" . "</tr>"; $prog_titles = $row['titles']; $prog_titles = explode(',' , $prog_titles); $table .= "<tr>" . "<td>".$row['id']. "</td>" . "<td>".$row['views']. "</td>" . "<td>".$row['enabled']. "</td>" . "<td></td>" . "</tr>" . "<tr>" . "<td>Title ID</td>" . "<td>Name</td>" . "<td>Description</td>" . "<td>Image</td>" . "</tr>" ; foreach ( $prog_titles as $title ) { $sql2= mysql_query("SELECT * FROM titles WHERE title = '$title' "); $row2 = mysql_fetch_array($sql2); $table .= "<tr>" . "<td>" . $row2['id'] . "</td>" . "<td>" . $row2['title'] . "</td>" . "<td>" . $row2['description'] . "</td>" . "<td>". "<img width='50px' src='images/" . $row2['img'] . "'/></td>" . "</tr>" ; } // close foreach $table .= "</table>"; echo $table; echo "<br /><br /><br />"; } // close while ?> <br /> <br /> <FORM action="export.php"> <INPUT type="submit" value="Export to XLS"> <INPUT type="hidden" value="<?php print $table;?>" name="export"> </FORM> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/216364-posting-tables-into-xls/ Share on other sites More sharing options...
Buddski Posted October 20, 2010 Share Posted October 20, 2010 You said it was working before you made this loop change.. What errors are you getting in the export.php function now? Also.. how much data is stored in the tables variable? Personally I would be sending the export script your variables and getting it to get the data instead of posting it.. Keep in mind PHP's max_post_size Quote Link to comment https://forums.phpfreaks.com/topic/216364-posting-tables-into-xls/#findComment-1124343 Share on other sites More sharing options...
kirkh34 Posted October 20, 2010 Author Share Posted October 20, 2010 well there are no errors... when i open the xls it just shows the one table of data instead of the multiple tables... when I had the loop just adding the rows inside one single table it exported and showed everything fine... there isn't much data just a few rows... Quote Link to comment https://forums.phpfreaks.com/topic/216364-posting-tables-into-xls/#findComment-1124357 Share on other sites More sharing options...
Buddski Posted October 20, 2010 Share Posted October 20, 2010 Can you attach your export script? Quote Link to comment https://forums.phpfreaks.com/topic/216364-posting-tables-into-xls/#findComment-1124362 Share on other sites More sharing options...
kirkh34 Posted October 20, 2010 Author Share Posted October 20, 2010 <?php # header("Content-type: application/octet-stream"); # # # replace excelfile.xls with whatever you want the filename to default to # header("Content-Disposition: attachment; filename=program_report.xls"); # header("Pragma: no-cache"); # header("Expires: 0"); $table = $_GET['export']; if(isset($table)){ echo $table; }else{ header("Location: report.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216364-posting-tables-into-xls/#findComment-1124370 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.