title: How to render different Html everytime second loop runs php
body: <p>I have a page where I am displaying data from the database with PHP. I want to use the second HTML every time the second loop is executed.</p>
  <p>let's say we have 4 courses eg:</p>
  <ul>
  <li>1st course (default Html)</li>
  <li>2nd course (second Html)</li>
  <li>3rd course (default Html)</li>
  <li>4th course (second Html)</li>
  </ul>
  <p>I have tried doing <code>if ($i % 2 == 0) { // render second html }</code> it works but it renders the same course twice.</p>
  <p>How can I do this?</p>
  <pre><code>$i = 0;
  &lt;?php if (mysqli_num_rows($courses) &lt; 1) { ?&gt;
      &lt;h4&gt;No courses found.&lt;/h4&gt;
      &lt;?php } else {
      while ($course = mysqli_fetch_assoc($courses)) {
      ?&gt;
          &lt;div class=&quot;rs-history sec-spacer&quot;&gt;
              &lt;div class=&quot;container&quot;&gt;
                  &lt;div class=&quot;row&quot;&gt;
                      &lt;div class=&quot;col-lg-6 col-md-12 rs-vertical-bottom mobile-mb-50&quot;&gt;
                          &lt;a href=&quot;#&quot;&gt;
                              &lt;img src=&quot;&lt;?= $course['media'] ?&gt;&quot; alt=&quot;History Image&quot; /&gt;
                          &lt;/a&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;col-lg-6 col-md-12&quot;&gt;
                          &lt;div class=&quot;abt-title&quot;&gt;
                              &lt;h2&gt;&lt;?= $course['title'] ?&gt;&lt;/h2&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;about-desc&quot;&gt;
                              &lt;p&gt;&lt;?= $course['description'] ?&gt;&lt;/p&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;?php
          if ($i % 2 == 0) {
          ?&gt;
              &lt;div class=&quot;rs-mission sec-color sec-spacer&quot;&gt;
                  &lt;div class=&quot;container&quot;&gt;
                      &lt;div class=&quot;row&quot;&gt;
                          &lt;div class=&quot;col-lg-6 col-md-12 mobile-mb-50&quot;&gt;
                              &lt;div class=&quot;abt-title&quot;&gt;
                                  &lt;h2&gt;&lt;?= $course['title'] ?&gt;&lt;/h2&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;about-desc&quot;&gt;
                                  &lt;p&gt;&lt;?= $course['description'] ?&gt;&lt;/p&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;col-lg-6 col-md-12 rs-vertical-bottom mobile-mb-50&quot;&gt;
                              &lt;a href=&quot;#&quot;&gt;
                                  &lt;img src=&quot;&lt;?= $course['media'] ?&gt;&quot; alt=&quot;History Image&quot; /&gt;
                              &lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  &lt;?php    }
      }
  } ?&gt;
  </code></pre>