Note that there are some explanatory texts on larger screens.

plurals
  1. POCategory.php - products show in subcats but not in categories if it has no subcategories
    primarykey
    data
    text
    <p>Below is my <strong>category.php</strong> that uses a switch statement to either show subcategories or products. When i click on a subcategory, it displays the products like it's supposed to. However, if the category has NO SUBCATEGORIES, no products will show at all.</p> <p>Is this a case where the <strong>switch statement needs to be altered</strong>, the entire <strong>foreach loop needs to be in an if statement</strong> or is there <strong>something wrong with the db</strong> and the ids... all of my cats in the menu have a parent_id = 0, subcats correspond to the id for the category table, the products are assigned a category_id. Is this a JOIN thing?</p> <pre><code>&lt;?php foreach ($listing as $key =&gt; $list){ echo "&lt;img src='".$list['thumbnail']."' border='0' align='left' /&gt;"; echo "&lt;h4&gt;"; switch($level){ case "1": echo anchor('welcome/cat/'.$list['id'],$list['name']); break; case "2": echo anchor('welcome/product/'.$list['id'],$list['name']); break; } echo "&lt;/h4&gt;"; echo "&lt;p&gt;".$list['shortdesc']."&lt;/p&gt;&lt;br style='clear:both'/&gt;"; } ?&gt; </code></pre> <p>Any help is much appreciated.</p> <p>the $level is located in the welcome controller.</p> <pre><code>function cat($id){ $cat = $this-&gt;MCats-&gt;getCategory($id); if (!count($cat)){ redirect('welcome/index','refresh'); } $data['title'] = "Company |" .$cat['name']; if ($cat['parentid'] &lt; 1){ // show other cats $data['listing'] = $this-&gt;MCats-&gt;getSubCategories($id); $data['level'] = 1; }else{ // show products $data['level'] = 2; $data['listing'] = $this-&gt;MCats-&gt;getProductsByCategory($id); } $data['category'] = $cat; $data['main'] = 'category'; $data['navlist'] = $this-&gt;MCats-&gt;getCategoriesNav(); $this-&gt;load-&gt;vars($data); $this-&gt;load-&gt;view('template'); } </code></pre> <p>get products by category function... This selects the products based on category_id in the products table. still no show though...</p> <pre><code> function getProductsByCategory($catid){ $data = array(); $this-&gt;db-&gt;select('id,name,shortdesc,thumbnail'); $this-&gt;db-&gt;where('category_id',$catid); $this-&gt;db-&gt;where('status','active'); $Q = $this-&gt;db-&gt;get('products'); if ($Q-&gt;num_rows() &gt; 0){ foreach ($Q-&gt;result_array() as $row){ $data[] = $row; } } $Q-&gt;free_result(); return $data; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload