title: Adding Echo 0000 prefix according to mysql ID number
body: <p>I am building a POS with electronic invoices, because the invoice number will start with 1 and it is ugly to show invoice number : 1 I want to build something to add 00000 as prefix like this</p>
  
  <pre><code>$lastinvoice = mysqli_query($db, "SELECT * FROM `sales` 
      order by `id` DESC LIMIT 1");
  $last_invoice = mysqli_fetch_assoc($lastinvoice);
  $invoice = $last_invoice['id']+1;
  </code></pre>
  
  <p>building the prefix </p>
  
  <pre><code>$prefix=if (($invoice)&lt;10){echo '0000000'};
  elseif (($invoice)&lt;100){echo '000000'};
  elseif (($invoice)&lt;1000){echo '00000'};
  elseif (($invoice)&lt;10000){echo '0000'};
  elseif (($invoice)&lt;100000){echo '000'};
  elseif (($invoice)&lt;1000000){echo '00'};
  elseif (($invoice)&lt;10000000){echo '0'};
  </code></pre>
  
  <p>Now in the HTML form I submit a hidden input like this</p>
  
  <pre><code>&lt;input type="hidden" name="set_invoice"
      value="&lt;?php echo "$prefix$invoice"?&gt;"&gt;
  </code></pre>
  
  <p>I am getting error with the builded prefix, it is not well made but because I am new to PHP I just do not know how to do that...</p>
  
  <p>Any ideas ?</p>
  
  <p>The error is</p>
  
  <blockquote>
    <p>PARSE ERROR: SYNTAX ERROR, UNEXPECTED 'IF' (T_IF) IN /HOME/LOCAL/PUBLIC_HTML/*******/SALES.PHP ON LINE 6</p>
  </blockquote>
  
  <p>and Dreamweaver marks all the builded $prefix as bad coded</p>
  
  <p>NOT A DUPLICATED</p>
  
  <p>It is not a duplicated question. What I need is not only leading zeros but to check the last invoice and accoding to this apply the ammount of zeros and the links to the "duplicated" posted by someone does not solve the problem because is not the same kind of question ...</p>