Populate a Dropdown list with MySQL data and select options in a edit page
Look for instructions on how tp populate a edit field with the correct info from a database
i can create a dynamic drop down list but it down diplay the correct info in the database from the add page.
i can create a dynamic drop down list but it down diplay the correct info in the database from the add page.
Comments
But where's the Content??
content
RE: But where's the Content??
This is a request for a tutorial. Hopefully someone will write it or provide a link to such a tutorial.
Martha Graham
DMXzone.com
Code snippet for DWMX php/mySQL dropdown list
You have to look at come code, but this shouldn't be TOO scary.
What you're trying to get is HTML that looks like this:
<select name="ship_type">
<option value="2" >Next Day</option>
<option value="1" >Fedex</option>
<option value="3" SELECTED>UPS Ground</option>
</select>
The first thing to do is create a recordset with your value and display fields. On the Application->Bindings window press the '+' sign and choose Recordset. If the "Advanced..." button is showing, click it to switch to Advanced view. Give your recordset a name - I used "rsShipType". In the SQL text box, type something like:
SELECT ship_type_id, ship_type_name
FROM ship_type
ORDER BY ship_type_name
Or, you can use the buttons at the bottom of the dialog to build your SQL query. Click Test to verify your code, and press OK to save it when you're happy.
Next, you want to modify the snippet of code below and paste it into the Code View of your page where the dropdown should be. I usually type some junk characters in the design view ('yyy', for example), select them, then switch to code view. Then paste your code over the selected characters.
Here's the code:
<select name="ship_type">
<?php do { ?>
<option value="<?php echo $row_rsShipType['ship_type_id']?>"
<?php if (!(strcmp($row_rsShipType['ship_type_id'],
$row_rsOrder['ship_type_id']))) {echo "SELECTED";} ?>>
<?php echo $row_rsShipType['ship_type_name']?>
</option>
<?php } while ($row_rsShipType = mysql_fetch_assoc($rsShipType)); ?>
</select>
In the code above, search for "rsShipType" and replace it with your recordset name. Replace "ship_type_id" with your identifier column and "ship_type_name" with your display column name. I also have a recordset called rsOrder that I'm using to set the "SELECTED" row. You should change this as appropriate.
The PHP "do while" statement loops through the recordset and adds an "option" line for each row.
You must me logged in to write a comment.