View Full Version : Need help on looping through function code

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

function get_category($id=null){
//displaying categories is better to store it in an array
$query=mysql_query("SELECT `id`,`name` FROM `categories`");
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


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.

Clement OSei

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

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

I have solve it

Thanks once again

Clement Osei