I need to generate an invoice number from an integer of a table with an auto incrementing ID of the database where the user purchases saved.
Example of the table invoice database:
The invoice number format floor do one of two ways.
Example 1: of the number of invoices without prefix:
0000001 | 0000002 | 0000003 | 0000004 | 0000005
Example 2: the number of invoices with prefixes:
F-0000001 | F-0000002 | F-0000003 | F-0000004 | F-0000005
Question:
1) ¿What is the best way to do this, you can do directly from MySQL or PHP?
2) ¿What is the most appropriate format Example 1 or Example 2?
I appreciate your support as always!
PHP, originally derived from Personal Home Page Tools, now stands for PHP: Hypertext Preprocessor, which the PHP FAQ describes as a "recursive acronym." PHP executes on the server, while a comparable alternative, JavaScript, executes on the client.
PHP is used for server-side programming which will interact with databases to retrieve information, storing, email sending, and provides content to HTML pages to display on the screen. HTML is used for specifying colors, text formatting, aligning, etc. PHP is easy to learn but not as much as HTML.
Python is better than PHP in long term project. PHP has low learning curve, it is easy to get started with PHP. Compare to PHP Python has lower number of Frameworks. Popular ones are DJango, Flask.
PHP is known to be the most frequently used programming language. According to W3Techs, 78.8% of all websites are using PHP for their server-side. Interesting fact: PHP originally stood for Personal Home Page. Now PHP is widely known and thought of as Hypertext Preprocessor.
Thanks to Gordon Linoff, I could get a way to solve this.
I will share an example, perhaps someone may be interested.
SQL - Invoice without prefix: SELECT id, LPAD(id,7,'0') FROM invoice WHERE id = 1;
Result: 0000001
SQL - Invoice with prefix: SELECT id, CONCAT( 'F-', LPAD(id,7,'0') ) FROM invoice;
Result: F-0000001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With