title: While loop, statement for every other loop?
body: <p>I have a while loop and each one displays a <code>&lt;li&gt;&lt;/li&gt;</code> in a list, is there a way to tell php that every other loop should echo say:</p>
  
  <pre><code>&lt;li style="background: #222;"&gt;&lt;/li&gt;
  </code></pre>
  
  <p>and in my css I would have another colour #111 set as default so users of my site can easily determine which row of data they are seeing?</p>
  
  <p>my code as requested:</p>
  
  <pre><code>function user_details($dbc, $q, $details) {
  echo '&lt;ul class="userlist"&gt;';
  while ($user = $q -&gt; fetch(PDO::FETCH_ASSOC)) {
  
      echo '&lt;li&gt;&lt;span&gt;(' . $user['id'] . ')&lt;/span&gt; &lt;a href="/viewaccount?id=' . $user['id'] . '"&gt;' . $user['username'] . '&lt;/a&gt;&lt;div&gt;';
  
      if ($user['admin'] &gt; 0) {
          echo '&lt;img class="Tooltip" src="gameimages/admin.png" width="18" height="18" title="Is game admin." alt="" /&gt;';
      }
  
      echo '&lt;img class="Tooltip" src="gameimages/' . $user['gender'] . '.png" width="18" height="18" title="' . $user['gender'] . '" alt="" /&gt;';
  
      $last_active = time() - $user['last_active'];
      $seconds = $last_active % 60;
          $minutes = ($last_active - $seconds) / 60;
      if ($minutes &lt;= 4) {
      echo '&lt;img class="Tooltip" src="gameimages/active5.png" width="18" height="18" alt="" title="';
          if ($seconds == 0) {
              echo 'Last active ' . $minutes . ' minutes ago." /&gt;';
          }
          elseif ($minutes == 0) {
              echo 'Last active ' . $seconds . ' seconds ago." /&gt;';
          }
          else {
              echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." /&gt;';
          }
      }
      elseif ($minutes &lt;= 9) {
          echo '&lt;img class="Tooltip" src="gameimages/active10.png" width="18" height="18" alt="" title="';
          if ($seconds == 0) {
              echo '&lt;strong&gt;Last active ' . $minutes . ' minutes ago." /&gt;';
          }
          else {
              echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." /&gt;';
          }
      }
      elseif ($minutes &lt;= 14) {
          echo '&lt;img class="Tooltip" src="gameimages/active15.png" width="18" height="18" alt="" title="';
          if ($seconds == 0) {
              echo 'Last active ' . $minutes . ' minutes ago." /&gt;';
          }
          else {
              echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." /&gt;';
          }
      }
  
      if ($user['subscriber'] &gt; 0) {
          echo '&lt;img class="Tooltip" src="gameimages/subscriber.png" width="18" height="18" title="Subscriber with ' . $user['subscriber'] . ' days left." alt="" /&gt;';
      }
  
      echo '&lt;/div&gt;';
  
      echo '&lt;a href="#"&gt;&lt;img class="Tooltip" src="gameimages/sendmessage.png" width="18" height="18" title="Send ' . $user['username'] . ' a message." alt="" /&gt;&lt;/a&gt;';
  
      $is_friend = $dbc -&gt; prepare("SELECT id, friend_id FROM friends WHERE id = ? &amp;&amp; friend_id = ?");
      $is_friend -&gt; execute(array($details['id'], $user['id']));
      $friend_request = $dbc -&gt; prepare("SELECT id, id_to FROM friend_requests WHERE id = ? || id_to = ? &amp;&amp; id = ? || id_to = ?");
      $friend_request -&gt; execute(array($user['id'], $details['id'], $details['id'], $user['id']));
      if ($is_friend -&gt; rowCount() &gt; 0) {
          echo '&lt;img class="Tooltip" src="gameimages/isfriend.png" width="18" height="18" title="Friend request sent to ' . $user['username'] . '." alt="" /&gt;';
      }
      elseif ($friend_request -&gt; rowCount() &gt; 0) {
          echo '&lt;img class="Tooltip" src="gameimages/friendrequested.png" width="18" height="18" title="There is a request pending to be friends with ' . $user['username'] . '." alt="" /&gt;';
      }
      else {
          echo '&lt;a href="/confirm?action=addfriend&amp;amp;id=' . $user['id'] . '"&gt;&lt;img class="Tooltip" src="gameimages/addfriend.png" width="18" height="18" title="Add ' . $user['username'] . ' as a friend." alt="" /&gt;&lt;/a&gt;&lt;/li&gt;';
      }
  }
  echo '&lt;/ul&gt;';
   }
  </code></pre>
  
  <p>It is in a function at the min, basically each other row should have another background :)</p>