Jump to content

Drop Down Menu Populated from MySQL, kind of working...


suttercain

Recommended Posts

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.

 

<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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.