title: Generate a continuous invoice number in PHP & MySQL (concurrency)
body: <p>The system is used by many shops, and each shop has its own invoice number, e.g.</p>
  
  <pre><code>SHOPA-0001
  SHOPA-0002
  SHOPA-0003
  
  SHOPB-0001
  SHOPB-0002
  ...
  </code></pre>
  
  <p>Now what I did is, select the last ID in MySQL table, and +1 to the invoice number. My problem is, 1 shop has multiple PC running this system, if 2 cashier submit the form at same time, it will has duplication.</p>
  
  <p>Any suggestion to this problem?</p>