title: Display items from database in HTML/PHP
body: <p>I'm trying to display some items on webpage from a database. I have a function that loops through the data stored in the database. Currently it displays the last item that appears within the database rather than the first or anything else. I have tried ordering the items by the id but it gives the same result. I have also tried to display individual items of the array but it just displays the first character of the last item within the database.</p>
  
  <h2>display items function:</h2>
  
  <pre><code>&lt;?php
      function get_product_details()
      {
          global $db;
          $ret = array();
          $sql = "SELECT * FROM Products";
          $res = mysqli_query($db, $sql);
  
          while($ar = mysqli_fetch_assoc($res))
          {
              $ret[] = $ar;
          }
          return $ret;
      }
  ?&gt;
  </code></pre>
  
  <h2>Area for displaying items:</h2>
  
  <pre><code>&lt;article class = "main_area2"&gt;
              &lt;h1 class = "food_h1"&gt;Menu&lt;/h1&gt;&lt;br&gt;
              &lt;section class = "menu_section"&gt;
                  &lt;?php 
                      $products = get_product_details(); 
  
                      foreach($products as $ap)
                      {
                          $name = $ap['pro_name'];
                          $description = $ap['descr'];
                          $price = $ap['rrp'];
                      }
                  ?&gt;
                  &lt;div class = "section_4"&gt;
                      &lt;h1 class = "food_h2"&gt;&lt;?php echo $name; ?&gt;&lt;/h2&gt;
                      &lt;br&gt;&lt;img src = "img/products/hassellback_pot.jpg" class = "img_dis"&gt;
                      &lt;br&gt;&lt;h1 class = "food_h2"&gt;&lt;?php echo $description; ?&gt;&lt;/h1&gt;
                      &lt;br&gt;&lt;h1 class = "food_h2"&gt;£ &lt;?php echo $price; ?&gt;&lt;/h1&gt;
                      &lt;button class = "basket_btn" type = "button"&gt; Buy &lt;/button&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>This is the current display and as you can see the first and last are exactly the same (the second to eighth are currently hard-coded).</p>
  
  <p><a href="https://i.stack.imgur.com/zvxTI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zvxTI.png" alt="Display page"></a></p>
  
  <p>P.S. Don't worry about closing the section &amp; article with the close tags because it's already done. </p>