title: Use PHP while loop to create advance filter
body: <p>I have a problem and that is I want to create a link on a website like people can click the link to show certain products only depending on percentage. like for example, i have a column in my database with discount percentage and it will show min discount and max discount. assuming we have min and max discount. $min=12 and $max=94; and I want to put them in links to show only products with certain discounts only like filtering. below is the example of the link.</p>
  
  <pre><code>    &lt;a href="#"&gt;12% to 20%&lt;/a
      &lt;a href="#"&gt;21% to 30%&lt;/a&gt;
      &lt;a href="#"&gt;31% to 40%&lt;/a&gt; and so on until it reaches 
      &lt;a href="#"&gt;81% to 90%&lt;/a&gt; and the last will be 
      &lt;a href="#"&gt;91% to 94%&lt;/a&gt;
  </code></pre>
  
  <p>smallest and largest numbers will be coming from a column from database and they can change frequently. i came up with solution and its working fine but my code is too long and its like I took to many steps which could be done in few lines of code. I have pasted my working code below but I am sure this can be reduced to few lines of code.</p>
  
  <pre><code>$catsql25 = "SELECT MAX(down_percentage) as largest FROM hot_deals";
  $catquery25 = mysqli_query($conn, $catsql25);
  while ($row25 = mysqli_fetch_array($catquery25, MYSQLI_ASSOC)){
      $largest_number = $row25['largest'];
  }
  
  $catsql26 = "SELECT MIN(down_percentage) as smallest FROM hot_deals";
  $catquery26 = mysqli_query($conn, $catsql26);
  while ($row26 = mysqli_fetch_array($catquery26, MYSQLI_ASSOC)){
      $smallest_number = $row26['smallest'];
  }
  
  $array_tens = array(10,20,30,40,50,60,70,80,90,100);
  
  
  foreach ($array_tens as $value){
  
      if(($value - $smallest_number &lt;= 10) &amp;&amp; ($value - $smallest_number &gt; 0)){
          echo '&lt;a href="/exp.php?fst='.$smallest_number.'&amp;lst='.$value.'"&gt;&lt;div class="lfmen2"&gt;';
          echo $smallest_number." to ".$value."&lt;/div&gt;&lt;/a&gt;";
          $next_num = $value + 1;
          $next_ten = 9;
          $stop_num = floor($largest_number / 10);
          $stop_num2 = $stop_num * 10;
          //echo $stop_num2.'&lt;br&gt;';
          $num_rounds = $stop_num2 - $value;
          $num_rounds2 = $num_rounds / 10;
          //echo $num_rounds2;
          for ($i = 1; $i &lt;= $num_rounds2; $i++){
          $end_num = $next_num + $next_ten;
          echo '&lt;a href="/exp.php?fst='.$next_num.'&amp;lst='.$end_num.'"&gt;&lt;div class="lfmen2"&gt;';
          echo $next_num;
          echo " to ";
          echo $end_num;
          echo "&lt;/div&gt;&lt;/a&gt;";
          $next_num += 10;
          $end_num += 10;
          }
      }
  }
  
  
  foreach ($array_tens as $value2){
  
      if(($largest_number - $value2 &lt; 10) &amp;&amp; ($largest_number - $value2 &gt; 0)){
          $lsst = $value2 + 1;
          if($lsst != $largest_number){
          echo '&lt;a href="/exp.php?fst='.$lsst.'&amp;lst='.$largest_number.'"&gt;&lt;div class="lfmen2"&gt;'.$lsst." to ".$largest_number."&lt;/div&gt;&lt;/a&gt;";
          }
          elseif($lsst == $largest_number){
              echo '&lt;a href="/exp.php?fnly='.$largest_number.'"&gt;&lt;div class="lfmen2"&gt;'.$largest_number.'&lt;/div&gt;&lt;/a&gt;';
          }
      }
  
  }
  </code></pre>
  
  <p>I know its all mess but..
  Thanks.</p>