0

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?

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by chupinette
0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.