Hello all,

i have a question regarding a mysql populated selectbox, i managed to fill this with data from a table, but now i want to show the selected value from another table ( with the same value of course).

here is my selectbox now:

<select name="project" class="selectbox" tabindex="1"> 
<?php
$sql = "SELECT descr FROM project"; 
$rs = mysql_query($sql); 
while ($r = mysql_fetch_array($rs)) {
echo "<option value=\"".$r["descr"]."\">".$r["descr"]."</option>"; 
} 
?>
 </select>

in another table, called 'build' i store the same descr as in the project table, i want to select that one, by id that is, and show that one as selected in the selectbox.

can anyone help me out?

Initially store the descr of the selected one (get it from mysql).
Then in your while loop, you check if $r == $your_new_variable;

If it is, then you echo "selected" in your <option> tag.

commented: thanks for helping +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.