...

View Full Version : Downloading Search Results



tomyknoker
07-03-2007, 01:16 AM
hi all... I have a pretty simple search quesry which outputs the search results onto a php page... i added a link to a php page which would download the results into an excel format... but i am getting the following error...


Please enter a search term.
Warning: Invalid argument supplied for foreach() in /home/html/admin/downloadResults.php on line 31

Warning: Cannot modify header information - headers already sent by (output started at /home/html/admin/downloadResults.php:19) in /home/html/admin/downloadResults.php on line 52

Warning: Cannot modify header information - headers already sent by (output started at /home/html/admin/downloadResults.php:19) in /home/html/admin/downloadResults.php on line 53
Array

my download page looks like this...


<?php
include 'library/configure.php';
include 'library/open.php';

if (!isset($_GET['q']) || $_GET['q'] == '') {
header('Location: index.php');
}

else {


/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);

/*check if search term was entered*/

if (!$searchterm) {
echo 'Please enter a search term.';
}

/*add slashes to search term*/

if (!get_magic_quotes_gpc()) {
$searchterm = addslashes($searchterm);
}

$count = 0;
$results = Array();

foreach ($searchColumns as $column) {

/*loop through the columns and query the database*/

$results[] = mysql_query("SELECT * FROM `tblmembers` WHERE `$column` LIKE '%$searchterm%");
}

$tsv = array();
$html = array();

for ($i=0; $i<$count; $i++) {
while($row = mysql_fetch_array($result[$i], MYSQL_NUM)) {
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
}

$tsv = implode("\r\n", $tsv);
$html = "<table>" . implode("\r\n", $html) . "</table>";
}

$fileName = 'mysql-to-excel.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");

echo $tsv;
//echo $html;

}

include 'library/close.php';
?>

_Aerospace_Eng_
07-03-2007, 01:25 AM
I think what is occuring is because no search term was entered the foreach is missing some information that needs. The easiest way to get around this is to add @ before the foreach function executes this way any errors are supressed. You may want to define something for the search term if no search terms are entered.

tomyknoker
07-03-2007, 01:37 AM
But I get that error even when a search term is entered...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum