Forum Moderators: coopster
<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?
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":
<?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:
while ($row = mysql_fetch_array($event,MYSQL_NUM)) Any input would be appreciated, or any tutorials to point me in the right direction.
thanks
[edited by: jatar_k at 6:29 am (utc) on Dec. 6, 2004]
[edit reason] no personal urls thanks [/edit]
If you only have five fields and you are referencing $row[5], that may be the source of your problem as indexing starts with 0 by default (so it would be $row[0] through $row[4]).
Like I said, that may be oversimplistic but (without knowing your db schema) could be an oversight.
Josh
while ($row = mysql_fetch_array($event...
You're using $event as your result pointer while the pointer you've set is $result. Try:
while ($row = mysql_fetch_array($result...
Also, as bubone2 pointed out, your offsets may be off--though this wouldn't cause the while... line error. Only you know your database structure. You could make your code clearer in one or both of a couple ways. In your $query, you could say
$query = "SELECT event, venu, seat, cost, quantity
FROM tickets
WHERE event like '%$event%'";
...substituting whatever the actual db column names are. That way you can be sure that $row[0] is the event, $row[1] is the venu, etc. Also, that should be a little more efficient because you aren't selecting more data from the table than you need.
And/or, since you are using mysql_fetch_array(), you could access the data with the associative index rather than the numerical one, like $row['event'], $row['venu'], etc. That would make it a little clearer what you are doing in your while loop.
I hope this helps.