Array number crops value instead of choosing key?

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Array number crops value instead of choosing key?

Post 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
*/
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Array number crops value instead of choosing key?

Post 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. :|
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Array number crops value instead of choosing key?

Post by requinix »

$row_test is ONE result from the query, not all of them.
Put your mysql_fetch_array inside the loop.
Post Reply