Page 1 of 1

Dynamic list and producing row on the form page

Posted: Sun Dec 05, 2004 9:22 pm
by drunkenmonkey79
I have created the following dynamic drop down:

Code: Select all

<form method="post" action="test.php3"> 		
<?php

$db = mysql_connect("x", "y", "z");	
mysql_select_db("db114469701",$db);

$sql = "SELECT event FROM tickets ORDER BY event ASC"; 
					
$result = mysql_query($sql) OR die(mysql_error());
						
echo '<select name="event">';
while ( $row = mysql_fetch_object($result) )

{
echo '<option>' .$row->event. '</option>';
}
echo '</select>';
?>
<input type=submit value="next"></td></form>
On the page the form is pointing to, test.php3, I am able to call out $event and that event (cell) is returned, but how would I return the whole row instead of just the $event value?

I have an example http://www.fobsgonewild.com/tickets/mainsearch.php

If you go to the link above and you choose an item from the drop down, then click next, that item is output on the following screen using the $event variable. I want the whole row to print also.

I tried doing something like this on "test.php3":

Code: Select all

<?php
<? 
echo "$event<br>"; 

if ($event)    
   { 
    mysql_connect('x','y','z') or die ("Problem connecting to Database"); 
    mysql_select_db(d) or die( "Unable to select database"); 
     
    $query = "select * from tickets WHERE event like '%$event%'";      
     
    $result = mysql_query($query) or die("Unable to select Database"); 
    if (!$result) die("select * from tickets WHERE event like $event failed: ".mysql_error()); 
     
    if  ($result) 
    { 
    echo "<font face='Arial, Helvetica, sans-serif' color='#000000'>Your search for $event produced the following result:</font><br><br>"; 
    echo "<table width=90% align=center border=1><tr> 
        <td align=center bgcolor=#009999><font face='Arial, Helvetica, sans-serif' color='#FFFFFF'><b>Event</b></font></td> 
        <td align=center bgcolor=#009999><font face='Arial, Helvetica, sans-serif' color='#FFFFFF'><b>Venue</b></font></td> 
        <td align=center bgcolor=#009999><font face='Arial, Helvetica, sans-serif' color='#FFFFFF'><b>Seat</b></font></td> 
        <td align=center bgcolor=#009999><font face='Arial, Helvetica, sans-serif' color='#FFFFFF'><b>Cost</b></font></td> 
        <td align=center bgcolor=#009999><font face='Arial, Helvetica, sans-serif' color='#FFFFFF'><b>Quantity*</b></font></td> 
        </tr>"; 

        while ($row = mysql_fetch_array($event,MYSQL_NUM)) {     // Begin while 
            echo "<tr><td align="left">$row[1]</td><td align="left">$row[2]</td><td align="left">$row[3]</td><td align="left">$row[4]</td><td align="left">$row[5]</td></tr>\n"; 
        }                  // end while 
        echo "</table>"; 
     } else { echo "problems...."; } 
   } else { 
   echo "Your search was empty. <br> Click back on your browser and type an event to search"; 
   } 
include ('links.x'); 
?> 
?>
and I am getting an error on the following line from the above code:

Code: Select all

while ($row = mysql_fetch_array($event,MYSQL_NUM))
Any input would be appreciated, or any tutorials to point me in the right direction.

thanks

Posted: Sun Dec 05, 2004 10:30 pm
by scorphus
You are passing a string ($event) to mysql_fetch_array. You should pass a valid result to it. A result is returned i.e. by mysql_query(). Then just pass $result to mysql_fetch_array() like this:

Code: Select all

<?php
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {     // Begin while
?>
Or just this:

Code: Select all

<?php
while ($row = mysql_fetch_row($result)) {     // Begin while
?>
Read the reference for [php_man]mysql_fetch_array[/php_man].

-- Scorphus

thanks!

Posted: Mon Dec 06, 2004 8:50 am
by drunkenmonkey79
Thanks Scorphus, I changed $events to $results and that fixed everything!

Much appreciated.

:D