title: How can i generate a unique incremental id like an invoice number (PHP)
body: <p>Please how can I generate a unique id that increments when a new invoice is created.
  For example, I have an invoice with the id NR20200001 so the Next invoice created the  Id should be NR20200002.</p>
  <p>This is my code below, I can't seem to increment the unique id I generated, so I just generated it randomly, but I need to generate it incrementally</p>
  <pre><code>&lt;?php 
      $qry = &quot;SELECT * from requisitions order by req_id desc&quot;;
      $result = mysqli_query($connection, $qry);
      $row    = mysqli_fetch_array($result);
      $lastid = $row['req_id'];
  
      if($lastid == &quot;&quot;){
          $number = &quot;NR&quot;.date(&quot;Y&quot;).date(&quot;s&quot;);
      }
      else{
          $length=2;
          $number = substr($lastid,4);
          $number = intval($number);
          $number = &quot;NR&quot;.date(&quot;Y&quot;).date(&quot;s&quot;).substr(str_shuffle(str_repeat($x='0123456789',ceil($length/strlen($x)))),1,$length);
      }
  ?&gt;
  </code></pre>