Re: newbie PHP/HTML pull down menu problem
| From: | Justin French | Date: | Wed, 14 Aug 2002 14:40:32 +0000 |
| Subject: | Re: newbie PHP/HTML pull down menu problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-112541@lists.php.net to get a copy of this message | ||
You have a while loop that pulls values out of the MySQL table row by row,
and for each row, you output an option in the select box.
Something like:
<form name="tester" action="script.php" method="get">
<select name="color">
<?
$sql = "SELECT color_id, color FROM colors_table ORDER BY id";
$result = mysql_query($sql);
while($myrow = mysql_fetch_array($result))
{
$color_id = $myrow['color_id'];
$color = $myrow['color']
echo "<option value=\"{$color_id}\">{$color}</option>";
}
?>
</select>
</form>
Season to taste :)
Justin French
on 14/08/02 2:30 PM, Brian & Shannon Windsor (bwindsor@mindspring.com)
wrote:
> Hi,
>
> I want to pull information out of my mySQL database and use it as a pull
> down menu ona web page. There are two sets of information that I need, one
> is a color, and the other is the color_id, so I want to use it in the way
> below but without having to physically enter all the data. I'd like to use
> color_id as the value and the actual color name as the text in the pull down
> button. Can someone please help me on how to pass the info into a useable
> way to get the info out of PHP and into HTML? I've haad no problems going
> from HTML to PHP, but can't seem to grasp going the other way, especially
> with a list of things. I've been banging my head against this for two days,
> but something tells me it's extremely easy.
>
> Thanks,
>
> Brian
>
> <form name="tester" action="script.php" method="get">
> <select name="color">
> <option value="1">red
> <option value="2">blue
> <option value="3">black
> <option value="4">ice
> <option value="5">purple
> </select>
> </form>
>
>
>