Jump to content

Drop down menu choices and selected with mySQL content


petenaylor

Recommended Posts

Hi all

 

I need to combine these two scripts:

 

Firstly, the following decides which out of the following list is selected based on its value in the mySQL table:

 

<select name="pack_choice">

<option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option>

<option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option>

<option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option>

</select>

 

Although this works OK, I need it also to show dynamic values like this:

 

select name="category">

<?php

$listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC");

while($categoryReturned=mysql_fetch_array($listCategories)) {

echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>";

}

?>

</select>

 

I'm not sure if this is possible?

 

Many thanks for your help.

 

Pete

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.