Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Downloading Search Results

    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 Code:
    <?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';
    ?>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    But I get that error even when a search term is entered...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •