Hi all:
I have a while-loop displaying rows from one MySQL table as HTML tables of dynamically generated content. Within this loop I have another while-loop that generates a <select> menu from another MySQL table.
I wish an item within the <select> menu to be 'selected' thus: <option value=\"$x\" if($x == $y {echo 'selected'}>$x</option> where $x is a var from one table and $y is a var from another, but I am unsure of how to compare the two values $x and $y as they come from seperate queries. Basically I want the var: '$usr_affs' from the first query to be matched with the var: '$activity' from the second query in order for the relevant item to be selected.
Here is what I have thus far:
while($row = mysql_fetch_array($result)) {
$usr_affs = $row['affiliation'];
//Create select drop-down list
$act_sql="SELECT sportID FROM $table_spt";
act_result=mysql_query($act_sql,$connection) or header("Location: error.php?err=query");
$activityselect = "<select name=\"user_06\"><option>--choose one--</option>";
while($row=mysql_fetch_array($act_result)){
$activity = $row['sportID'];
$activityselect .= "<option value=\"$activity\" if($activity = $usr_affs){ echo 'selected'; }>$activity</option>";
}//end-while
$activityselect .= "</select>";
//'$activityselect' is then echoed within each dynamically generated table (each row //returned from the D😎:
<table border=\"0\" width=\100%\" etc etc>
<tr>
<td>$activityselect</td>
</tr>
</table>
Has anyone come across any similar problems such as this??
Many thanks in advance:
Russ