populate the drop down list on html with data from the dbase

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lodae
Forum Newbie
Posts: 1
Joined: Tue Mar 10, 2009 4:24 am

populate the drop down list on html with data from the dbase

Post by lodae »

How to populate the drop down list on html with data from the database
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: populate the drop down list on html with data from the dbase

Post by Benjamin »

lodae wrote:How to populate the drop down list on html with data from the database
Query the database and use PHP to create an html drop down list.
EPX
Forum Newbie
Posts: 19
Joined: Fri Nov 21, 2008 3:22 am
Location: Stafford, UK

Re: populate the drop down list on html with data from the dbase

Post by EPX »

This is a very basic way:


<select name="drop_down">
<option value="">Select from list</option>
<?php
while($row = mysql_fetch_array($rsquery))
{?>
<option value="<?php echo $row['var1'];?>"><?php echo $row['var2'];?></option>
<?php
}?>
</select>

Hope thats something useful.
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: populate the drop down list on html with data from the dbase

Post by Paul Arnold »

Here's an example

Code: Select all

 
<select name="field_name">
<?PHP
    $getData = "SELECT * FROM table_name";
    $getData_q = mysql_query($getData, $connection);
    while($getData_r = mysql_fetch_assoc($getData_q)) {
?>
    <option value="<?PHP echo $getData_r['field']; ?>"><?PHP echo $getData_r['field']; ?></option>
<?PHP 
    }
?>
</select>
 
Post Reply