Re: Re: Dynamically populating a dropdown box
| From: | Ian Ferger | Date: | Fri, 14 Dec 2001 18:41:24 +0000 |
| Subject: | Re: Re: Dynamically populating a dropdown box | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-15034@lists.php.net to get a copy of this message | ||
also, to get existing vals to show in the select as default,
<select name="colorz">
while($row=mysql_fetch_array($result)){
$selected=($row["ID"]==$ID)?"selected":"";
echo "<option value='" . $row["ID"] . "' $selected>" .
$row["name"] .
"</option>\n";
}
</select>
the value can be in single quotes also, altho i dont think quotes matter
unless you use opera or some other wierdass browser (you can also put
doubles using \")
I believe (correct me if im wrong) that since echo is a construct and not a
predefined function, it runs faster.
"Matt Stewart" <matt@netvirtua.com> wrote in message
news:95C78551DA8AD41182CB00E018C2447E285C64@comms.netvirtua.int...
> yep, that's basically what i use for this sort of thing - it's a nice
short
> simple function, and works a treat. Obviously if you'd rather be passing
the
> actual colour name to the next step, you use printf("<option
> value=%s>%s</option>", $myrow["colorname"],
> $myrow["colorname"]);
> I also prefer to use printf("<option value=\"%s\"> so it has the value in
> quotes - just a fussy html thing i do though.
>
> -----Original Message-----
> From: Matthew Crouch [mailto:whyyousee@yahoo.com]
> Sent: 13 December 2001 22:58
> To: php-db@lists.php.net
> Subject: [PHP-DB] Re: Dynamically populating a dropdown box
>
>
> I'm no expert, and my code is probably buggy, but I think this is the gist
> of it:
>
> <select name="color">
> <?
> $result = mysql_query("SELECT * from colors");
> while ($myrow = mysql_fetch_array($result)) {
> printf("<option value=%s>%s</option>", $myrow["colorid"],
> $myrow["colorname"]);
> }
> ?>
> </select>
>
>
> Chris Payne wrote:
>
> > Hi there everyone,
> >
> > I have a shopping cart which is starting to work nicely, but I have to
> select size/color from the entries, how do I do this dynamically in PHP
with
> MySQL? I need them to be dropdown form boxes but haven't got a clue how
to
> populate them from the fields of my database.
> >
> > Please help me with example code if possible, it would be greatly
> appreciated :-)
> >
> > Thank you everyone
> >
> > Regards
> >
> > Chris
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.306 / Virus Database: 166 - Release Date: 04/12/01
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.306 / Virus Database: 166 - Release Date: 04/12/01
>