Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP & MySQL - Generate invoice number from an integer from the database

Tags:

php

mysql

invoice

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:

enter image description here

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!

like image 624
Learning and sharing Avatar asked Nov 09 '15 04:11

Learning and sharing


People also ask

What PHP stand for?

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.

What is PHP or HTML?

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.

Which is better Python or PHP?

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.

Is PHP used anymore?

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.


1 Answers

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

like image 195
Learning and sharing Avatar answered Sep 29 '22 07:09

Learning and sharing