suttercain Posted April 19, 2007 Share Posted April 19, 2007 Hi guys, I am trying to get a drop down populated using two tables and the where clause: <form action="view_review.php" method="post"> <?php $sql3 = "SELECT comic_id FROM reviews"; if ($result3 = mysql_query($sql3)) { if (mysql_num_rows($result3)) { $row3 = mysql_fetch_assoc($result3); echo $row3['comic_id']; } } $result2 = mysql_query("SELECT title FROM comics WHERE comic_id='" . $row3['comic_id'] . "'") or die(mysql_error()); echo "<select name='title'>"; while($row2 = mysql_fetch_array($result2)){ echo "<option value='" . $row2['title'] . "'>" . $row2['title'] . "</option>'"; } echo "</select>"; ?> </td> </tr> <tr> <td><input type="submit" name="submit" value="Up, Up and Away!"></form></td> It's only populating one and not echoing through the while loop. Any suggestions to resolve this? Thanks guys. Link to comment https://forums.phpfreaks.com/topic/47781-drop-down-menu-populated-from-mysql-kind-of-working/ Share on other sites More sharing options...
Barand Posted April 19, 2007 Share Posted April 19, 2007 Isn't comic_id unique, therefore there is only one comic with that id for it loop through. Link to comment https://forums.phpfreaks.com/topic/47781-drop-down-menu-populated-from-mysql-kind-of-working/#findComment-233461 Share on other sites More sharing options...
per1os Posted April 19, 2007 Share Posted April 19, 2007 <form action="view_review.php" method="post"> <?php $sql = "SELECT reviews.comic_id, comics.title FROM reviews LEFT JOIN (comics) ON (reviews.comic_id=comics.comic_id) ORDER BY comics.title;"; $result = mysql_query($sql) or DIE("Unable to populate Dropdown: " . mysql_error()); if (mysql_num_rows($result) > 0) { echo "<select name='comics'>"; while($row = mysql_fetch_array($result)){ echo "<option value='" . $row['comic_id'] . "'>" . $row['title'] . "</option>'"; } echo "</select>"; } ?> </td> </tr> <tr> <td><input type="submit" name="submit" value="Up, Up and Away!"></form></td> Give that a try. Link to comment https://forums.phpfreaks.com/topic/47781-drop-down-menu-populated-from-mysql-kind-of-working/#findComment-233476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.