Display products from a specific category in a multilevel category application php mysql pdo oop -


i creating simple app, rusty code, , new oop don't seem understand logic creating simple link display products relevant category. app not ecommerce pulls data database, displays it, when user clicks on link, , writes data in products , category tables. interface trying way display linking products when user clicks on respective categories. problem categories multilevel , there stuck, have no idea how pass variable, or pull appropriate select statement. problem i have been browsing , trying ate examples show how display product listings , none multilevel subcategories. need add url link category associated product. have 2 simple tables, , dynamic menu.

-- -- table structure table `products1` --  create table if not exists `products1` ( `id` int(11) not null auto_increment, `name` varchar(32) not null, `description` text not null, `price` int(11) not null, `category_id` int(11) not null, `created` datetime not null, `modified` timestamp not null default current_timestamp, primary key (`id`) ) engine=myisam  default charset=latin1 auto_increment=14 ;  -- -- table structure table `menu` --  create table if not exists `menu` ( `id` int(11) not null auto_increment, `name` varchar(255) character set utf8 not null, `parent_id` int(11) not null,  primary key (`id`)  ) engine=innodb  default charset=utf8 collate=utf8_bin auto_increment=136 ; 

the table menu way relate parent categories siblings. have on 103 categories, related each other parent id, have no idea, how write logic display active category in menu. logic flawed. can't figure out kind of comparison need do, hat code needs done pass right category id, depending on active li tag is.

this menu generated table.

        <?php          $items = $rows;         $id = '';         echo '<ul class="dl-menu">';         foreach($items $item){             if($item['parent_id'] == 0) {                 echo '<li><a href="?category=<?php echo $category->id?>">'.     $item['name'] . '</a>';                 $id = $item['id'];                 sub($items, $id);                 echo '</li>';             }         }         echo "</ul>";         function sub($items, $id){             echo '<ul class="dl-submenu">';             foreach($items $item){             if($item['parent_id'] == $id) {                 echo '<li><a href="?category=<?php echo $category->id?>">'. $item['name'] . '</a>';         //      $id = $item['id'];                 sub($items, $item['id']);                 echo '</li>';                 }             }             echo '</ul>';         } ?> 

my problem line of code echoes category id. have no idea script need output that, mean logic need compare result.

your current lines output category id following:

echo '<li><a href="?category=<?php echo $category->id?>">' . $item['name'] . '</a>'; 

as these eachos within php, don't need tags inside echo, changing lines :

echo '<li><a href="?category=' . $category->id . '">'. $item['name'] . '</a>'; 

should fix problem, if understanding question correctly.


Comments