Re: Drop Down Menus

From: Date: Wed, 13 Feb 2002 05:06:07 +0000
Subject: Re: Drop Down Menus
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-16886@lists.php.net to get a copy of this message
here is an example from my page: <? $connection = mysql_connect($databaseserver, $databaseuser, $databasepass) or die("Can't connect to DB"); $db = mysql_select_db($databasename, $connection); $sql= "SELECT id, State FROM $statetable ORDER BY State ASC"; $result= mysql_query($sql, $connection); print "<select name=\"State\">"; while ($row = mysql_fetch_array($result)) { $id = $row["id"]; $State = $row["State"]; print "<option>$State</option>"; } print "</SELECT>" ?> "Peter Lovatt" <pjln1@sunmaia.net> wrote in message news:NFBBKAGAILLHPFOOAKFICEHGCOAA.pjln1@sunmaia.net... > Hi > > the row index starts at 0 not 1 so you need $row[0], as you have only one > field $row[1] will be empty. > > HTH > > Peter > > ----------------------------------------------- > Excellence in internet and open source software > ----------------------------------------------- > Sunmaia > www.sunmaia.net > info@sunmaia.net > tel. 0121-242-1473 > ----------------------------------------------- > > > -----Original Message----- > > From: Bzdpltd@aol.com [mailto:Bzdpltd@aol.com] > > Sent: 12 February 2002 16:10 > > To: php-db@lists.php.net > > Subject: [PHP-DB] Drop Down Menus > > > > > > Hi wonder if anyone knows what I am doing wrong here. > > > > I have a drop down selection menu that is generated from a mysql > > database. In the database we have over 15 fields one of them > > contains text for the catergory that the entry belongs to. I have > > used the following code to generate my drop down menu but when i > > view it in the browser the drop down menu has not listed the > > categories instead we have blank entries for each selection. > > > > <? mysql_connect("localhost","user","password"); > > mysql_select_db("database"); > > $sql = "select distinct category from books ORDER BY category ASC"; > > $makes_result = mysql_query($sql); > > print ("<select name=\"category\">\n"); > > print("<option selected value=\"\">Please select a > > Category</option>\n"); > > while($row = mysql_fetch_row($makes_result)) > > { > > print("<option value=\"$row[1]\">$row[1]</option>\n"); > > } > > print("</select>"); ?> > > > > Thanks for the help. > > > > Barry > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.db (#16886) next »