Trouble printing query results

Discussion in 'PHP' started by SeriousNovice, Feb 2, 2008.

  1. #1
    Seriously confused and teaching myself...

    I'm attempting to print one field from each of the 6 rows returned from a query. I've been fiddling with this on and off yesterday and today and have tried various punctuation, functions and so forth. I've tried printing all the fields and just one of them. I get the following error message/notice in the Web site error log, not in the browser itself -

    PHP Notice: Undefined variable: event_state in /var/www/bdsm/bdsm_gz.php on line 55​

    Here is the code that I'm using -

    <?php
    /* Open connection to the "events" database here*/
    mysql_connect(The string to connect is here and it works) or die("Failure to communicate with database: ' . mysql_error()");
    mysql_select_db("officialeventlocator_com_events") or die ("Could not open database events. Error: " . mysql_error());
    /* Specify and run the query here - select ALL the fields based on the WHERE clause */
    $result_events = mysql_query( "SELECT * from event_info WHERE event_state='GZ' AND to_date >='$cur_date'");
    /* If info is recovered, this should return true and print the number of events in the state.*/
    $num_rows = mysql_num_rows( $result_events );
    print "<p>$num_rows events are in the table for the State of Gizzard</p>\n";
    ?>

    /*The above works fine. The problem begins here when I try to print JUST the value of the variable "event_state".*/

    <?php
    /*This routine should print the information, about the individual events, to the screen. There's no formatting yet, just text.*/
    print "<p>Begin printing query results-</p>\n";

    /*And that's as far as the printing goes. Since there are six rows in the query results, the error is generated six times and the page stops.*/

    while ($row = mysql_fetch_row($result_events))
    {
    print $event_state;
    }
    mysql_close();

    ?>

    The very simple code for the printing was taken from one of the books that I am using for reference. The results of this can be seen at bdsm.officialeventlocator.com/bdsm_gz.php . I've been using this page to see that each step works before I go on to the next and the wording is admittedly silly.

    Thanks in advance...


    Steve E.
     
    SeriousNovice, Feb 2, 2008 IP
  2. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Try it with while ($row == mysql_fetch_row($result_events))
     
    nile1483, Feb 2, 2008 IP