Page 1 of 1

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

Posted: Tue Mar 10, 2009 4:35 am
by lodae
How to populate the drop down list on html with data from the database

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

Posted: Tue Mar 10, 2009 4:39 am
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.

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

Posted: Tue Mar 10, 2009 5:12 am
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.

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

Posted: Tue Mar 10, 2009 5:12 am
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>