displaying table rows with a dropdown?
Posted: Sun Mar 08, 2009 7:46 pm
Hi guys, you've been pretty helpful with my newbie questions.
I was wondering if it was possible to display MYSQL table data by a drop down box? I've looked for a bunch of tutorials but can't seem to find anything. Currently I'm using this code to display the data itself.
I'm trying to create a drop down that displays the data depending what campus is selected. So my SQL would be:
I was wondering if it was possible to display MYSQL table data by a drop down box? I've looked for a bunch of tutorials but can't seem to find anything. Currently I'm using this code to display the data itself.
Code: Select all
<?php
$connection = mysql_connect("localhost", "username", "password") or die("Error connecting to database");
mysql_select_db("database", $connection);
$result = mysql_query("SELECT * FROM room ORDER BY roomId", $connection) or die("error querying database");
$i = 0;
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo "class='body1'";}?>>
<td>
<?php echo $result_ar['roomName']; ?></td>
<td>
<img src=<?php echo $result_ar['roomPicture']; ?>>
</td>
<td>
<?php echo $result_ar['roomItem1']; ?></td>
</td>
<td>
<?php echo $result_ar['roomItem2']; ?></td>
</td>
<td>
<?php echo $result_ar['roomItem3']; ?></td>
</td>
<?php
$i+=1;
}
?>Code: Select all
SELECT `roomName` , `roomPicture` , `roomItem1` , `roomItem2` , `roomItem3` , `maxpeople`
FROM `room`