I use mysql for inserting data into dropdown menu. I got multiple dropdown menus - each dropdown menu has name id
- this information i get from database($stmt
). The content of each dropdown menu I get by another mysql query $stmt2
.
I need to determine which id
was set in every dropdown menu. These values I need to use later. This is my solution, which doesn't work. It won't print out anything.
echo "<table class ='centered_div' border='1px solid black'>";
echo "<tr><td>ID</td><td>food</td><td>g</td></tr>";
while($rows = $stmt->fetch()){
echo "<tr><td>" . $rows['id'] . "</td><td>".$rows['food'];
echo "<form action='upravit_plan.php' method='post'><select name =".$rows['id']." > ";
$stmt2 = $db->query($q2);
echo "<option value ='nothing'> choose one </option>";
while($rows2 = $stmt2->fetch())
{
echo '<option value = '.$rows2['id'].'>'.$rows2['food'].'</option>';
}
echo "</select></form>";
echo "</td> <td>" . $rows['g'] . "g</td></tr><br> ";
};
echo "<tr><td colspan='3'><form action='upravit_plan.php' method='post'><input name = 'go' type='submit' value='OK'/></form></td></tr>";
echo "</table>";
if(isset($_POST['go']))
{
$stmt = $db->query($q);
while ($rows = $stmt->fetch())
{
echo $_POST[$rows['id']]; // trying to print values
}
}