Page 1 of 1

array key problem

Posted: Tue Oct 06, 2009 1:06 am
by m2babaey
Hi
I place a piece of code and its result. I don't know why array value is not shown.
Even when I use array_key_exists(), it returns false
this is the code:

Code: Select all

$sql = mysql_query("SELECT * FROM brokerprices");
while (list($name,$value) = mysql_fetch_row($sql)) {
$result[$name]=$value;
}
print_r($result);
echo "<br><br>But there should be '0.79' that is not:".$result[ASAS];
Image

Re: array key problem

Posted: Tue Oct 06, 2009 2:48 am
by robnet
what do you mean 'array value'?

What is the output you would like to see?

Re: array key problem

Posted: Tue Oct 06, 2009 2:52 am
by m2babaey
I mean array content
I'd like to be able to see 0.75 when I run echo $result[ASTC];

Re: array key problem

Posted: Tue Oct 06, 2009 3:06 am
by robnet
Slight syntax warning - if you turn on error reporting (which is useful anyway during dev) you will probably find it complains about an undefined constant (ASTC) because it's looking for a constant called ASTC rather than a string. Surround it in quotes to fix this:

Code: Select all

echo $result['ASTC'];
I don't think that's the ultimate problem but once error reporting is on hopefully it will reveal itself :)