Jump to content

Instance of two classes


chupinette

Recommended Posts

Hello all :)

I wanted to know of it is possible to create instances of two different classes in a single php page? Im trying to display a list of categories and another list of brands. But I am getting only the categories as result...

this is what i have done:

<?php $obj = new CategoryList();if (method_exists($obj, 'init')){	$obj->init(); }for($i = 0;$i< count($obj->mCategory); $i++)		{echo "<a href=''>";	echo $obj->mCategory[$i]['name']. "<br/>";	echo "</a>"; }   $obj2 = new BrandList();if (method_exists($obj2, 'init')){$obj2->init(); }for($i = 0;$i< count($obj2->mBrand); $i++){echo "<a href=''>";	echo $obj2->mBrand[$i]['name']. "<br/>";	echo "</a>"; } ?><?php

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

}
for($i = 0;$i< count($obj->mCategory); $i++)		
{
echo "<a href=''>";	
echo $obj->mCategory[$i]['name']. "<br/>";	
echo "</a>";

}



$obj2 = new BrandList();
if (method_exists($obj2, 'init'))
{
$obj2->init();

}
for($i = 0;$i< count($obj2->mBrand); $i++)
{
echo "<a href=''>";	
echo $obj2->mBrand[$i]['name']. "<br/>";	
echo "</a>";

}

?>


 

Link to comment
https://forums.phpfreaks.com/topic/186684-instance-of-two-classes/
Share on other sites

Thanks for your reply! I think Ive put the code twice..

Can you please tell me why only the categories are being displayed?

Here's the code again:

<?php

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

}

for ($i = 0; $i < count($obj->mCategory); $i++)
{
	echo "<a href=''>";
	echo $obj->mCategory[$i]['name'] . "<br/>";
	echo "</a>";

}


$obj2 = new BrandList();
if (method_exists($obj2, 'init'))
{
	$obj2->init();

}
for ($i = 0;$i < count($obj2->mBrand); $i++)
{
	echo "<a href=''>";
	echo $obj2->mBrand[$i]['name'] . "<br/>";
	echo "</a>";

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.