Hello all :)
Well, im trying to display a list of categories from values fetched from my database. I have a class called CategoryList which has the function initialise as below:
GetCategory actually uses PDOStatement::FetchAll

public function init()
{
	$this->mCategory = Catalog::GetCategory(); 
	print_r($this->mCategory);
}

Then i have my index.php where I need to display the list of categories

$obj = new CategoryList();
if (method_exists($obj, 'init'))
{
     $obj->init();	
}

I get the following result
Array ( [0] => Array ( [category_id] => 1 [name] => Doors and Windows ) [1] => Array ( [category_id] => 2 [name] => Electrical ) )

What i want is something like:
Doors and Windows
Electrical
I have tried

for($i = 0 ; $i < 10; $i++ )
    $obj->mCategory[$i].name ;

But I get ERRNO: 8
TEXT: Use of undefined constant name - assumed 'name'

Can anyone help me with this please?

Hi again :)
Ive been able to solve part of the problem. ;)
This is what I have done:

public function init()
{
	$this->mCategory = Catalog::GetCategory();
	$result = Catalog::GetCategory(); 
	for($i = 0;$i< count($this->mCategory); $i++)
	{
		echo $this->mCategory[$i]['name'];	
		echo "<br/>";
	}
}

Now i get something like:
Category 1
Category 2
in index.php

<ul class="left_menu">
        <li class="odd">
             <a href="x.htyzml">
	<?php
		$obj = new CategoryList();
		if (method_exists($obj, 'init'))
		{
			$obj->init();	
		}
	?>
	</a>
        </li>

The code above actually displays the values in one link. I want to loop through the values adn display the categories in several links. Can Anyone help plz?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.