Im looking to create a series of drop down boxes which are populated from a MYSQL database.
I have 2 tables in the database,
id, name -
1|hot
2|cold
3|wormid, ids from table #1 (1, 3, 4) -
1|1, 3, ...
2|2, 3, ...
3|1, 2, ...
I need to select records from table 2 and create dropdown menus using the names from table 1.
Ive used the following code to create a dropdown lists, but it displays only one dropdown list and stops.
Any help is much appreciated
<?php
$getRss = mysql_query("SELECT * FROM optionals_groups where resid=".$_SESSION['restaid']." order by id asc");
while ($rss = @mysql_fetch_array($getRss)) { ?>
<select name="a_<?=$rss['id']?>" id="a_<?=$rss['id']?>" >
<option value="1" >Select Options</option>
<?php
$ot=0;
$last_ot="";
$goptionals=explode(', ',($rss['goptionals']));
$getRss= mysql_query("SELECT * FROM optionals order by id asc");
while ($rsso = mysql_fetch_array($getRss)) {
if (in_array($rsso['id'],$goptionals)) {
$ot++;
$last_ot=$rsso['optional'];
?>
<option value="<?=$rsso['id']?>" ><?=$rsso['optional']?></option>
<?php
}
}
?>
</select>
<br />
<?php } ?>
UPDATE
Here is where I am so far. I was able to create the dropdown lists using table 2 and I need to figured out how to get the names from table 1 for each id I have listed from table 2.
I have the feeling that something with join will do the job, but not quite sure.
Any ideas?
<?php
$getRss = mysql_query("SELECT * FROM optionals_groups where resid=".$_SESSION['restaid']." order by id asc");
while ($rsr = @mysql_fetch_array($getRss)) {
$goptionals=explode(', ',($rsr['goptionals']));
echo "<select name='a_".$rsr['id']." id='a_".$rsr['id']."' >";
echo "<option value='1' >Select Options</option>";
foreach($goptionals as $v)
{
echo "<option value=".$v." >".$v."</option>";
}
echo "</select><br>";
}?>