i am using a jquery accordian for display a list with sub items. i have a category table and product table. i want to fetch these categoris and corresponding products to the list. in my controller i add the below code.
$category=$this->Category->find('list',
array('fields'=>array('id','category_name')));
$this->set('category',$category);
$productlist=$this->Product->find('list',
array('fields'=>array('id','product_name','category_id')));
$this->set('productMenu',$productlist);
And in my list i added the list values
<ul id="nav"><?php
foreach ($category as $key => $value)
{
?><li><a href="#"><?php echo $value; ?></a>
<ul class="sub">
<?php foreach ($productMenu as $key => $value )
{ ?>
<li><a href="#"><?php echo $value; ?></a>
<?php } ?>
</ul>
</li><?php
}
?></ul>
Now the category is showing well, and i didont get the logic to add products that belongs to particular categry. if anybody know this please help me. iam stucking..
also when i debug this result i got the result
debug($catgory)
array(
(int) 1 => 'Crowns And Bridges Non Metal',
(int) 2 => 'Crowns And Bridges Metal',
(int) 3 => 'Implants',
(int) 4 => 'Dentures'
)
debug($product)
array(
(int) 1 => array(
(int) 1 => 'Lava',
(int) 2 => 'ZR Crown'
),
(int) 2 => array(
(int) 3 => 'Porcelain fused to metal crowns'
),
(int) 3 => array(
(int) 4 => 'General Restorative',
(int) 5 => 'Customised Abutments',
(int) 6 => 'Avinent Implants'
),
(int) 4 => array(
(int) 7 => 'Partial Dentures',
(int) 8 => 'Complete Dentures:'
)