Re: Populating a list box from a database - The code

From: Date: Sat, 28 Dec 2002 17:55:33 +0000
Subject: Re: Populating a list box from a database - The code
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-129513@lists.php.net to get a copy of this message
$Organisation[1] is always going to be empty because you're only selecting one item per row from the DB.... SELECT OrgName.... If you want the same output in both places, just do this... echo ( "<option value=\"$Organisation[0]\">$Organisation[0]\n" ); Denis L. Menezes wrote:
<select name="OrgName[]" size=5 id="OrgName" >
            <?php     //connecting to the database
$link = mysql_connect("localhost","lodestone","trypass"); if ($link){ Print ""; } else { Print "No connection to the database"; } if (!mysql_select_db("catapult_com")){
    Print "Couldn't connect database";
} else { Print ""."<br>\n"; } $sql="SELECT OrgName From TableResults ORDER BY OrgName"; $result=mysql_query($sql); While($Organisation=mysql_fetch_array($result)) { Print("<OPTION VALUE=\"$Organisation[0]\">$Organisation[1]\n"); } ?> </select>
-- By-Tor.com It's all about the Rush http://www.by-tor.com

« previous php.general (#129513) next »