title: Listing pages according to the number of entries in a database using PHP
body: <p>I'm writing a code in PHP that gets the number of products in the database, and lists them in pages accordingly.
  Here's the code I have so far :    </p>
  
  <pre><code>            &lt;?php 
                  $numProds=10;
                  if($numProds%9 == 0) {
                      $numPages = $numProds/9;
                  } elseif ($numProds%9 != 0) { // true
                      $numPages = floor($numProds/9) + 1; // $numPages = 2;
                  }
                  for ($i = 1; $i &lt; $numPages+1; $i++) {
              ?&gt;
                  &lt;li id="page&lt;?php echo $i; ?&gt;"&gt;
                      &lt;?php if($numProds &lt;= 9) {
                              for ($i = 1; $i &lt; $numProds+1; $i++) { ?&gt;
                                  &lt;div class="product" id="prodId&lt;?php echo $i; ?&gt;"&gt;
                                      &lt;div class="productImage"&gt;&lt;img class="image" src="images/sampleImg.png" /&gt;&lt;/div&gt;
                                      &lt;div class="prodInfo"&gt;
                                          &lt;h2&gt;&lt;a href="#"&gt;Red Strawberry Keyring blabla bla bla&lt;/a&gt;&lt;/h2&gt;
                                          &lt;b&gt;Price: $2.50 |&lt;/b&gt; &lt;a href="#"&gt;Add to cart&lt;/a&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                      &lt;?php
                              }
                          } else {
                              $numProds-=9;
                              for ($i = 1; $i &lt; 10; $i++) {  ?&gt;
                                  &lt;div class="product" id="prodId&lt;?php echo $i; ?&gt;"&gt;
                                      &lt;div class="productImage"&gt;&lt;img class="image" src="images/sampleImg.png" /&gt;&lt;/div&gt;
                                      &lt;div class="prodInfo"&gt;
                                          &lt;h2&gt;&lt;a href="#"&gt;Red Strawberry Keyring blabla bla bla&lt;/a&gt;&lt;/h2&gt;
                                          &lt;b&gt;Price: $2.50 |&lt;/b&gt; &lt;a href="#"&gt;Add to cart&lt;/a&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                      &lt;?php   }
                          }?&gt;
                  &lt;/li&gt;
                  &lt;?php } ?&gt;
  </code></pre>
  
  <p>I set a test value of 10, and I want every page to include 9 products.<br>
  That means I need 2 pages; one page with 9 products and another page with only 1 product.<br>
  First, I calculate the number of pages needed, and create the pages (AKA the <code>li</code>'s).<br>
  Secondly, In each page I have two if statements:<br>
  1) If numProds is smaller or equal to 9, create the exact number of products using a loop.<br>
  2) If numProds is bigger than 9 (i.e 10), create 9 products and take 9 off numProds so $numProds will be 1, which is the only number of products that should be created on the second page.</p>
  
  <p>The problem with this code is that all the pages include 9 products regardless of numProds, so something is wrong.<br>
  I went through the code a few times and found nothing.</p>
  
  <p>Another problem is that in each page the <code>&lt;li id="page&lt;?php echo $i; ?&gt;"&gt;</code> part starts from 0 again.<br>
  I know that's because of the loop, but my question is, is there a way to somehow continue the loop from the previous <code>$i</code> ?</p>