title: Displaying all items from mysql database
body: <p>I have <strong>table product</strong> and <strong>table category</strong> in my database. I want to display all category dynamically in a table and inside the table of each category I am displaying all item belonged to that category too.</p>
  
  <p>Those categories and items should be displayed like this :
  <a href="https://i.stack.imgur.com/Ps2KQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ps2KQ.png" alt="enter image description here"></a></p>
  
  <p>And here is my coding to do the work :</p>
  
  <pre><code>$fetch_cat = "SELECT * FROM tblcat"; //fetch from table category
  $result = $conn-&gt;query($fetch_cat);
  if ($result-&gt;num_rows &gt; 0)
  {
      while($cat_row = mysqli_fetch_assoc($result))
      {
          $cat_title = $cat_row['catName'];
          echo '&lt;table&gt;';
          echo '&lt;tr&gt;';
          echo '&lt;td&gt;&lt;img src="category/'.$cat_row['catImg'].'" /&gt;&lt;/td&gt;';
          echo '&lt;td&gt;';
          echo '&lt;ul class="content_init"&gt;';
  
          $stmt = "SELECT * FROM tblproduct WHERE prodCat = '".addslashes($cat_title)."' LIMIT 4"; //fetch from table product
          $result = $conn-&gt;query($stmt);
          if ($result-&gt;num_rows &gt; 0)
          {
              while($row = mysqli_fetch_assoc($result))
              {
                  echo '&lt;li&gt;';
                  echo '&lt;a href="#"&gt;&lt;img style="height: 188px; width: 188px;" src="user_images/'.$row['prodImg'].'" /&gt;';
                  echo '&lt;br /&gt;&lt;br /&gt;';
                  echo '&lt;h4&gt;'.$row['prodName'].'&lt;/h4&gt;';
                  echo '&lt;label&gt;&lt;span&gt;RM &lt;/span&gt;'.$row['prodPrice'].'&lt;/label&gt;&lt;/a&gt;';
                  echo '&lt;/li&gt;';
              }
          }
  
          echo '&lt;/ul&gt;';
          echo '&lt;/td&gt;';
          echo '&lt;/tr&gt;';
          echo '&lt;/table&gt;';
      }
  }
  </code></pre>
  
  <p><strong>Problem :</strong></p>
  
  <p>So the problem with my coding is, it can only display <strong>Category 1</strong> with items belonged to it. The rest categories unable to be displayed. I guess my coding might not loop properly because of bad programming as it unable to display the expected output.</p>