...

View Full Version : Need help on looping through function code



kingot
01-30-2012, 12:18 PM
Hi, i am creating a simple blog, which i have a function like this

<?php
function get_category($id=null){
//displaying categories is better to store it in an array
$categories=array();
$query=mysql_query("SELECT `id`,`name` FROM `categories`");
while($rows=mysql_fetch_assoc($query)){
$categories[]=$rows;
}
return $rows;
}
?>

which will display my blog topic category post at category_list.php

Now i loop through using a foreach loop ,here is the code

<?php

foreach(get_category() as $category){
echo $category['name'].'<br/>';
}
?>

Now it given me this error
! ) Warning: Invalid argument supplied for foreach() in C:\wamp\www\blog\category_list.php on line 12
Call Stack
Can some help me on how to loop through that function on the top.

Thanks
Clement OSei

mlseim
01-30-2012, 12:29 PM
Why does it have to be a function?
There's no reason to have a function?

kingot
01-30-2012, 12:36 PM
Hi ,
Thanks for your time helping me.

I have solve it

Thanks once again

Clement Osei



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum