I am using the following query to pull categories from the DB then creating a select list.

Can some tell me how to make the current value selected in the list when they open the category?

$queryc = "select * from tbl_category WHERE active = 'yes' ORDER by name ASC";
$resultc = mysql_query($queryc);
while ($rowc = mysql_fetch_array($resultc)) {
$catIDc = $rowc;
$namec = $rowc;
$activec = $rowc;

echo "<option value=$catIDc>$namec</option>";

Recommended Answers

All 4 Replies

I am not quite sure what you are wanting here.

Remember you can only select one item from a drop down by default and since you outputing all that are equal to yes I get confused as to the purpose of the while loop (unless there are many rows...which wouldnt work).

To set the default selected item on a drop down do it like so...

<option value="..." selected="selected"></option>

Could you offer more of an explantion?


Website Tutorials

//select db
$query="Select * from table";
   else {
   $options.="<option value='$id' $selected>$name</option>";
<form method="post" action="test.php">
Select something: <select name="select">
<?php echo $options; ?>
</select><br />
<input type="submit" name="submit" value="submit">


commented: Great answers. +1

Worked great, thanks.

You are welcome :)

Be a part of the DaniWeb community

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