Page 1 of 1

Array number crops value instead of choosing key?

Posted: Fri Nov 07, 2008 2:06 pm
by JAB Creations
I'm simply trying to echo a column of numbers that are fetched from a database. The problem is that when I attempt to select a key from the array ($row_test['game_cat_idx_game_cat_id'][$i]) it ends up cropping the item instead of choosing the key to echo. I always encounter this issue so an explanation would be greatly appreciated. :|

Code: Select all

$test = mysql_query("SELECT game_cat_idx_game_cat_id FROM game_cat_idx WHERE game_cat_idx_game_id ='39'");
$row_test = mysql_fetch_array($result4);
/*
20
24
19
16
15
*/
$count = mysql_num_rows($test); //5
echo 'count == '.$count;
while ($i < $count) {echo '<div>== '.$row_test['game_cat_idx_game_cat_id'][$i].'</div>'; $i++;}
/*
This echos...
== 2
== 0
==
==
==
==
== 
 
When I want it to echo...
== 20
== 24
== 19
== 16
== 15
*/

Re: Array number crops value instead of choosing key?

Posted: Fri Nov 07, 2008 3:19 pm
by JAB Creations
A strange note...

The MySQL query pulls the data in phpMyAdmin though PHP is not...? It's the exact same query so I'm at a total loss. :|

Re: Array number crops value instead of choosing key?

Posted: Fri Nov 07, 2008 4:59 pm
by requinix
$row_test is ONE result from the query, not all of them.
Put your mysql_fetch_array inside the loop.