RE: [PHP-DB] Drop down box NOT populated

From: Date: Fri, 23 Jan 2004 15:46:22 +0000
Subject: RE: [PHP-DB] Drop down box NOT populated
Groups: php.db 
Request: Send a blank email to php-db+get-32597@lists.php.net to get a copy of this message
Instead of: > $row = mysql_fetch_array($sql) Use: $row = mysql_fetch_assoc($sql) Humberto Silva World Editing Portugal -----Original Message----- From: John W. Holmes [mailto:holmes072000@charter.net] Sent: sexta-feira, 23 de Janeiro de 2004 15:42 To: lgs@sarreid.com; Tristan.Pretty@risk.sungard.com Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Drop down box NOT populated From: <Tristan.Pretty@risk.sungard.com> > Jsut a guess... > Your row has a capital 'A' in the SQL statement, and a lower case 'a' > in teh $row[] call.. > > does that matter? Yep, that would matter, but not the exact problem. I don't know if this thread has already been answered or not, so... The real problem is with this: > $sql = mysql_query("SELECT distinct(Account) FROM Backlog")or die > ("Something bad happened here: " . mysql_error()) ; > > echo "<select name=\"account\">\n"; > echo "<option>\n"; > > while ($row = mysql_fetch_array($sql)) > { > echo ' <option > > value="'.$row["account"].'">'.$row["account"]."</option>\n"; because there is no "account" index in $row. You're not selecting "account", you're selecting "distinct(Account)". So, you could do it the hard way and use $row['distinct(Account)'] as your value or change your SQL to: $sql = mysql_query("SELECT distinct(Account) AS acc FROM Backlog")or die and use $row['acc']. This is called making an alias. You alias the distinct(account) column to be called "acc". You can name the alias what ever you want. If you developed with your error_reporting() set to E_ALL, you'd have gotten a notice about "Undefined index 'account' in $row" that may have tipped you off to all of this. Hope this helps. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#32597) next »