Re: Drop down box NOT populated
| From: | John W. Holmes | Date: | Fri, 23 Jan 2004 15:41:35 +0000 |
| Subject: | Re: Drop down box NOT populated | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-32596@lists.php.net to get a copy of this message | ||
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...