title: PHP import images from directory into 2 column HTML row
body: <p>I have found some PHP that I am trying to adapt onto my page but can not seem to get it to work. Here is the code:</p>
  
  <pre><code>&lt;?php
  
  $pagetitle = "Test Gallery";
  $dirname = "img/folder_1/";
  $images = glob($dirname."*.jpg");
  
  ?&gt;
  
  
  &lt;?php $i=0; foreach($images as $image): ?&gt;
      &lt;?php if($i%2 === 0) echo '&lt;div class="row"&gt;' ?&gt;
          &lt;div class="col-sm-6"&gt;
              &lt;img class="lazy store-img" src="IMAGE_SOURCE" alt="" title=""&gt;
              &lt;h3&gt;IMAGE_NAME&lt;/h3&gt;
              &lt;button href="#" class="btn btn-primary"&gt;Purchase Image&lt;/button&gt;
          &lt;/div&gt;
      &lt;?php if($i%2 === 0) echo '&lt;/div&gt;' ?&gt;
  &lt;?php $i++; endforeach ?&gt;
  </code></pre>
  
  <p>I am trying to get the images to be pulled from a directory and each image is wrapped in a .col-sm-6 div then each 2 are wrapped in a .row div, then if there is an odd number of the files the last one would just be one .col-sm-6 div on its own. Below is the structure that I am trying to achieve:</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="col-sm-6"&gt;
         &lt;img class="lazy store-img" src="IMAGE_SOURCE" alt="" title=""&gt;
         &lt;h3&gt;IMAGE_NAME&lt;/h3&gt;
         &lt;button href="#" class="btn btn-primary"&gt;Purchase Image&lt;/button&gt;
      &lt;/div&gt;
     &lt;div class="col-sm-6"&gt;
         &lt;img class="lazy store-img" src="IMAGE_SOURCE" alt="" title=""&gt;
         &lt;h3&gt;IMAGE_NAME&lt;/h3&gt;
         &lt;button href="#" class="btn btn-primary"&gt;Purchase Image&lt;/button&gt;
      &lt;/div&gt;
   &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="col-sm-6"&gt;
         &lt;img class="lazy store-img" src="IMAGE_SOURCE" alt="" title=""&gt;
         &lt;h3&gt;IMAGE_NAME&lt;/h3&gt;
         &lt;button href="#" class="btn btn-primary"&gt;Purchase Image&lt;/button&gt;
      &lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>The IMAGE_NAME I would add something to pull through the imported filename so it can be displayed on the page and the IMAGE_SOURCE would be the images URL so for now please ignore those bits of text as I don't think it will affect this?</p>
  
  <p>I am new to PHP and just can't seem to find why nothing is showing on the page unless this code is not suited to my needs?</p>
  
  <p>P.s. if any of my syntax's are incorrect I apologies in advance.</p>