Hello friends,
I have one table with two columns in my mysql and a drop-down-menu in my php file. I would like to fill in a drop down menu with the elements of the first column and after a click on a submit button (if(isset($_POST[‘submit’])) condition) I want to select those elements on the drop-down-menu if they are the same with the elements on the second column. For example:
Column1
List item1
List item2
List item3
List item4
Column2
List item2
List item3
For this table the result should be a drop-down-menu with
List item1
List item2 selected
List item3 selected
List item4
Any idea how to do the loops? I need two loops, one embedded to the other. I tried to do it with two while-loops but it isn’t right.
<?php
<html><body><form action='test1.php' method='POST'>
echo"<select name='sub[]' size='7' width='300' style='width: 300px' multiple>";
$items1=mysqli_query($db, $sql1);
while($result_items1=mysqli_fetch_array($items1))
{
echo "<option value='".$result_items1['column1']."'";
if(isset($_POST['submit']))
{
$items2=mysqli_query($db, $sql2);
while($result_items2=mysqli_fetch_array($items2))
{
if($result_items1['column1']==$result_items2['column2'])
{
echo"selected";
}
}
}
echo"'>".$result_items1['column1']."</option>";
}
echo "</select></form></body></html>";
?>