title: Repeat category name - PHP SQL
body: <p>I created a database with 5 categories and created a page to display the available categories that I pull from the database. The problem is that I have 4 divs that have the following class ( col-md-3 ) and one that is ( col-md-6 ).</p>
  <p>Code for gathering the first 5 categories ( col-md-3 ):</p>
  <pre><code>&lt;?php 
      $this-&gt;db-&gt;limit(4); 
      $categories = $this-&gt;db-&gt;get_where('category', array('parent' =&gt; 0))-&gt;result_array(); 
      foreach ($categories as $key =&gt; $category):
  ?&gt;
      &lt;div class=&quot;gallery-item&quot;&gt;
          &lt;div class=&quot;grid-item-holder&quot;&gt;
              &lt;div class=&quot;listing-item-grid&quot;&gt;
                  &lt;img src=&quot;&lt;?php echo base_url('uploads/category_thumbnails/').$category['thumbnail'];?&gt;&quot; alt=&quot;&quot; /&gt;
                  &lt;div class=&quot;listing-counter&quot;&gt;                        
                      &lt;span&gt;2&lt;/span&gt;Locations
                  &lt;/div&gt;
                  &lt;div class=&quot;listing-item-cat&quot;&gt;
                      &lt;h3&gt;&lt;a href=&quot;&lt;?php echo site_url('home/filter_listings?category='.slugify($category['name']).'&amp;&amp;amenity=&amp;&amp;video=0&amp;&amp;status=all'); ?&gt;&quot;&gt;&lt;?php echo $category['name']; ?&gt;&lt;/a&gt;&lt;/h3&gt;
                      &lt;p&gt;&lt;?php echo $category['name']; ?&gt;&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  <p>Code for gathering another 1 category ( col-md-6 ):</p>
  <pre><code>&lt;?php 
      $this-&gt;db-&gt;limit(1); 
      $categories = $this-&gt;db-&gt;get_where('category', array('parent' =&gt; 0))-&gt;result_array(); 
      foreach ($categories as $key =&gt; $category):
  ?&gt;
      &lt;div class=&quot;gallery-item gallery-item-second&quot;&gt;
          &lt;div class=&quot;grid-item-holder&quot;&gt;
              &lt;div class=&quot;listing-item-grid&quot;&gt;
                  &lt;img src=&quot;&lt;?php echo base_url('uploads/category_thumbnails/').$category['thumbnail'];?&gt;&quot; alt=&quot;&quot; /&gt;
                  &lt;div class=&quot;listing-counter&quot;&gt;                        
                      &lt;span&gt;2&lt;/span&gt;Locations
                  &lt;/div&gt;
                  &lt;div class=&quot;listing-item-cat&quot;&gt;
                      &lt;h3&gt;&lt;a href=&quot;&lt;?php echo site_url('home/filter_listings?category='.slugify($category['name']).'&amp;&amp;amenity=&amp;&amp;video=0&amp;&amp;status=all'); ?&gt;&quot;&gt;&lt;?php echo $category['name']; ?&gt;&lt;/a&gt;&lt;/h3&gt;
                      &lt;p&gt;&lt;?php echo $category['name']; ?&gt;&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  <p>With this code, I get a display of categories but instead of displaying 5 categories, it repeats one of the displayed 4. How can I fix the code so that the display automatically continues to display the categories in all divs? If I forgot to write something, correct it or ask, I will update the question.</p>