I have a drop down list script in which it is populated from the database. I'm trying to Show the name on the list, but the actual value is the ID of the name. I think it'd be better to show my code to explain what I'm trying to do:
mysql_connect('localhost', 'user', 'pw');
mysql_select_db ("db");
$sqlId = "SELECT id FROM materials";
$sql = "SELECT name FROM materials";
$result = mysql_query($sql);
$resultId = mysql_query($sqlId);
echo "<td><select name='materials'>";
while ($row = mysql_fetch_array($result) && $row2 = mysql_fetch_array($resultId))
{
echo "<option value='" . $row2['id'] . "'>" .
$row['name'] . "</option>";
}
echo "</select></td></tr> ";
Every time I run this, the drop down list is never populated. What am I doing wrong?
SELECT id,name FROM materialsand subsequently, in the loop, only get one result row.