Page 1 of 1

array looping

Posted: Mon Dec 10, 2007 9:04 am
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

Posted: Mon Dec 10, 2007 9:17 am
by John Cartwright
its count($id) and not $count($id)

Posted: Mon Dec 10, 2007 9:20 am
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..