title: PHP counter increment in a while loop
body: <p>Im having a problem incrementing a counter in one of my while loops basically i just want to alternate between two image links that were fetched in my database but my counter wont increase and im not sure why can anyone help? </p>
  
  <pre><code>while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
        $img_link = $row['Image'];
        $img_link_alt = $row['Image_alt'];
        $i = 0;
  
         echo '&lt;div class="col-xs-6 col-sm-3 placeholder"&gt;'; 
         $img = ( $i % 2 == 0 ) ?  $img_link : $img_link_alt; 
  
              echo $i;
              //'?' . date("h:i:sa").'
              echo '&lt;img style="height:200px; border-radius:0%; width:300px;" src="screenshots/'. $img . '"&gt;';          
              echo '&lt;h4&gt;Screenshot&lt;/h4&gt;&lt;span class="text-muted"&gt;Updated Screenshot of the Botting session: &lt;b&gt;' . $row['script_name'] .' &lt;/b&gt;&lt;/span&gt;'; 
              echo '&lt;/div&gt;';        
              $i++;        
          }
  </code></pre>
  
  <p>Ive even tried declaring $i outside of the while loop and still nothing..... any help would be much appreciated </p>