0
votes

Okay i have a selection box(drop down menu) and a set of radio buttons.

Select Your Class:

<form action="" method="post">
<select name="class">
<option value="a">A</option>
<option value="b">B</option>
</select>
<br><br>

Red or blue:<br>
<input type="radio" name="red" value="red">Red
<input type="radio" name="blue" value="blue">Blue
</form>

I have connected my PHP script to database and retrieved the data from a table and stored them in variables to be echo out. ROW is Mysql fetch array .

$class = $row['class']
$color = $row['color']

How can i display it out in the radio button and selection box (normally for text box i set the value to <? php echo $foo ?>

Can someone help me?

1

1 Answers

0
votes
//read the data from database 

$row=mysql_fetch_row($result);
//assuming that the first data cell fetched is for dropdown list and the second is for radio button thats why $row[0] and $row[1] is used
<form action="" method="post">
<select name="class">
<option value="a" <?php if($row[0]=='a'){?> selected <?php } ?> >A</option>
<option value="b" <?php if($row[0]=='b'){?> selected <?php } ?> >B</option>
</select>
<br><br>

Red or blue:<br>
<input type="radio" name="red" value="red" <?php if($row[1]=='red'){?> checked<?php } ?>>Red
<input type="radio" name="blue" value="blue" <?php if($row[1]=='blue'){?> checked<?php } ?>>Blue
</form>