Jump to content

posting tables into xls


kirkh34

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

<?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");
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.