array looping

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
thatsme
Forum Commoner
Posts: 87
Joined: Sat Apr 07, 2007 2:18 am

array looping

Post by thatsme »

i have a query from which i gather 3 arrays

Code: Select all

while($fetch = mysql_fetch_array)
{
  $name[] = $fetch['name'];
  $id[] = $fetch['id'];
  $address[] = $fetch['address'];
  $image[] = $fetch['image'];

}
if i need to display the above values,

Code: Select all

echo $count($id) // not returning 0 even though there are no ids
var_dump is giving: array(1) { [0]=> NULL } 

if(count($id)>0)
{ 

for($i=0; $i<count($id); $i++)
{
   echo $name[$i];
   echo $address[$i];
   echo $image[$i];
}

}
I know that i can display the values in the while loop itself, but i wanted in an array. I am struck, help me out
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

its count($id) and not $count($id)
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Post by Corvin »

http://de3.php.net/manual/en/function.mysql-fetch-array.php wrote: array mysql_fetch_array ( resource $result [, int $result_type ] )
;)

Code: Select all

echo $count($id) // not returning 0 even though there are no ids
It's count(), not $count().

You should enable error reporting..
Post Reply