[thelist] PHP dropdown boxes.

Martin Kuplens-Ewart martin at takingitglobal.org
Sun May 26 21:25:01 CDT 2002


> Hi guys, just wanted to know how you put information taken from
> a datebase and inserting it into drop down boxes in html....

eh?

<select name="mydropdown">
<?
$vartocheckfor = ''; //set this via querystring or whatever.
$db = ''; //use this database in queries
$table = ''; //use this table in queries
$where = ' WHERE'; //use this var for extra settings
if($where == ' WHERE'){unset($where);} //just in case you don't use the
where var.
$q = mysql_query("SELECT * FROM $db.$table $where");
while($qd = mysql_fetch_assoc($q))
{
?>
  <option value="<?=$qd[Field1]?>"<?if($vartocheckfor == $qd[Field1]){?>
selected<?}?>><?=$qd[Field2]?></option>
<?
}
</select>
?>

Like that?
$vartocheckfor should be renamed to whatever the far to compare against
actually is. Nuke the line of code initialising it above before running,
otherwise it'll match no results.

Hth,

-m





More information about the thelist mailing list