Re: creating dropdown lists from fetched arrays.

From: Date: Mon, 25 Feb 2002 15:46:56 +0000
Subject: Re: creating dropdown lists from fetched arrays.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86098@lists.php.net to get a copy of this message
El dom, 24-02-2002 a las 17:39, Matthew Darcy escribió: > Hi, > > I want to create a dropdown list with options from a table. > > ie > <HTML> > <BODY> > > <?php > > $sql_select = "select * from dropdown_options"; > $results = mysql_query($sql_select); > > while ($row = mysql_fetch_array($results); > { > echo "<option VALUE=$row["col1"] NAME=option1>" > } > > </BODY> > </HMTL> > > I know this is basic but it is to give you an idea of what I want. > > I have tried to find an example of this in the book I am using to learn to > no result. > > I am guessing this is how it works from the info I have read from the book. > > Can someone put me on the right path. > > Thanks, > > Matt. With that semi-colon at the end of the while you are doing an empty loop... so when the script gets to the <option...> stuff... the array is empty. I would do something like this: <HTML> <BODY> <select name="myOptions"> <?php $sql_select = "select * from dropdown_options"; $results = mysql_query($sql_select); while ($row = mysql_fetch_array($results){ ?> <option value="<? print $row["id"] ?>"><? print $row["name"] ?></option> <? } ?> </select </BODY> </HMTL> _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com

« previous php.general (#86098) next »