array key problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

array key problem

Post 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
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: array key problem

Post by robnet »

what do you mean 'array value'?

What is the output you would like to see?
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Re: array key problem

Post by m2babaey »

I mean array content
I'd like to be able to see 0.75 when I run echo $result[ASTC];
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: array key problem

Post 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 :)
Post Reply