Click to See Complete Forum and Search --> : Dynamic menu in email


Siriunson
11-24-2007, 01:37 PM
I'm posting the results of a form with several drop menus that are populated from a database. The form posts ok but I am getting the number (_id) of the form item rather than the text label.

It is also being inserted into a database, so I wonder where I'm going wrong?

Thanks in advance.

h3r0
11-24-2007, 08:15 PM
<option value="'.$id.'">$name</option>

Is that what you have now? If you want the Name instead of the id, replace your option value with the name instead of the id.

Kyleva2204
11-25-2007, 12:20 AM
If your inserting data into a database the corresponds with the form data, its best to use an ID, that way you don't have things repeating in your database.. However, if you want to use both the ID and Name in the value, then set the value of the item to something like "1--Item1" and then on the resulting page have

$array = explode('--',$_POST['my_item']);
list($id,$item_name) = $array;

That will then populate $id, and $item_name with the.. id and item name.

hope this helps.

Siriunson
11-26-2007, 06:17 AM
Thank you both for your help. Using the advice offered, here, for others is my original code:

<select name="saladname" class="dropMenus" id="saladname">
<option value="0">select</option>
<?php
do {
?>
<option value="<?php echo $row_rsSalad['salad_id']?>"><?php echo $row_rsSalad['saladname']?></option>
<?php
} while ($row_rsSalad = mysql_fetch_assoc($rsSalad));
$rows = mysql_num_rows($rsSalad);
if($rows > 0) {
mysql_data_seek($rsSalad, 0);
$row_rsSalad = mysql_fetch_assoc($rsSalad);
}
?>
</select>
And here is the modified line:
<option value="<?php echo $row_rsSalad['saladname']?>"><?php echo $row_rsSalad['saladname']?></option>