Forum Moderators: coopster

Message Too Old, No Replies

Select boxes. Pass a variable and make sticky.

         

simon373

1:53 pm on May 17, 2006 (gmt 0)

10+ Year Member



Hi :)

I am creating a form and have a select box to select a client name and client id from the Client table, created as below:

<select name="client">';
$query="SELECT clientid,name FROM client ORDER BY name";
$result=@mysql_query ($query);
while(($row=mysql_fetch_assoc($result))){
echo"<option value=\"{$row['clientid']}\">{$row['name']}</option>\n";

}

echo'
</select></td>
<td>
<input type="submit" name="clientsubmit" value="Select"/>
<input type="hidden" name="id" value="TRUE"/>
</td>
</tr>
</form>

How do I take the selected client id and store it as a variable (to be assigned as clientid in another table) and how do I make the selected client stay selected after the form has been posted?

Many thanks for any help.

Simon.

omoutop

2:04 pm on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Q)How do I take the selected client id and store it as a variable (to be assigned as clientid in another table)

A) if the form of yours have mode=post, then $clientid=$_POST['client'];

Q)how do I make the selected client stay selected after the form has been posted?

A)
$query="SELECT clientid,name FROM client ORDER BY name";
$result=@mysql_query ($query);
while(($row=mysql_fetch_assoc($result)))
{
?>
<option value="<? echo $row['clientid'];?>"
<? if ($client==$row['clientid']) { echo " selected ";}?>
><? echo $row['name'];?></option>
<?
}
?>

simon373

8:00 pm on May 17, 2006 (gmt 0)

10+ Year Member



Thanks very much. Good advice:)