Hi All,
I hope this isn't a stupid question. I have a page that selects all the items in a database for display. The user can sort the columns and, through a dropdown box, filter the results by date. When they have the view they want, the user then has the option of downloading a .txt file of the result set.
The problem is I keep getting the entire database downloaded and not the filtered result set. I'm trying to add the SQL statement to the download button in a hidden field, but this isn't working (I don't even know if it's possible). I also tried to pass it through a query string, but that didn't work either. Here's a sample:
<?
$sql = "SELECT . . ."; <---- this contains a dynamic WHERE clause that is dependant upon the user's filter preference
?>
[DISPLAY RESULTS HERE]
' **** Then at the bottom of the result set ********
<form action="" method=post>
<input type="hidden" name="query" value="<? $sql; ?>">
<input type=submit name="btnDownload" value='Download File'>
</form>
<?
if($btnDownload){
$query = $_POST["query"];
$result = mysql_query($query);
header ("Content-Type: application/octet-stream");
header ("Content-Disposition: attachment; filename=\"result.txt\"");
while ($row = mysql_fetch_row ($result))
print (join ("\t", $row) . "\n");
mysql_free_result ($result);
}
?>
Any ideas? It seems like it would work, but obviously I'm missing something.
Geogal