Generate auto increment invoice number with prefix using php and mysql

This tutorial will teach you how to do auto generate  Invoice No using Php Mysql step by step i attached full source code below.i explained more clearly in the video tutorial attached below. [crayon-632f03ed0d00b659397258/] i have attached the video link below. which will do this tutorials step by step.  

Read More

  1. Home

    1. Public
    2. Questions
    3. Tags

    4. Users

    5. Companies

    6. Collectives

    7. Explore Collectives
    1. Teams

      Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?

    2. Teams

    3. Create free Team

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Ask Question

Asked 4 years, 3 months ago

Modified 4 years, 3 months ago

Viewed 3k times

-3

I would like to generate an auto increment invoice number using prefix.

Digits: 11 Prefix: B

From: B0000000001 to B0000000020.

Is there a easy way to do this in PHP?

  • php
  • sql
  • prefix
  • invoice

asked Jun 13, 2018 at 16:07

Dany BulletDany Bullet

11 silver badge2 bronze badges

1

  • 3

    What have you tried? str_pad and concatenation should make this pretty simple in php.

    – Devon

    Jun 13, 2018 at 16:09

Add a comment  | 

1 Answer

Sorted by: Reset to default

0

This is how you can do in in php.

$index = 11;
$prefix = 'B';
echo sprintf("%s%011s", $prefix, $index);

answered Jun 13, 2018 at 16:16

Jason KJason K

1,3961 gold badge9 silver badges15 bronze badges

1

  • echo sprintf() is an "antipattern". There is absolutely no reason that anyone should ever write echo sprintf() -- it should be printf() without echo every time.

    – mickmackusa

    Apr 16 at 3:21

Add a comment  | 

Not the answer you're looking for? Browse other questions tagged phpsqlprefixinvoice or ask your own question.

  • The Overflow Blog
  • Five nines uptime without developer burnout (Ep. 488)

  • We hate Scrum and Agile…when it’s done wrong (Ep. 489)

  • Featured on Meta
  • Recent Color Contrast Changes and Accessibility Updates

  • Reviewer overboard! Or a request to improve the onboarding guidance for new...

  • Should I explain other people's code-only answers?

Linked

92

How to make MySQL table primary key auto increment with some prefix

Related

2773

How can I prevent SQL injection in PHP?

3123

Add a column with a default value to an existing table in SQL Server

2271

How to concatenate text from multiple rows into a single text string in SQL Server

1291

Enumerations on PHP

2936

Deleting an element from an array in PHP

1239

Secure hash and salt for PHP passwords

2712

How do I get a YouTube video thumbnail from the YouTube API?

4114

How do I UPDATE from a SELECT in SQL Server?

4961

Reference — What does this symbol mean in PHP?

Hot Network Questions

  • Looking for a short story about the highest flight ever
  • Why does space warfare not lead to total anhiliation of both sides?
  • Saturnian Cloud Cities Pt. 3- Wind Turbine Problems
  • Can professors arrange for an MSc scholarship if you contact them by e-mail and they are interested in working with you?
  • How do you determine if there is a significant relationship between two variables with several factors affecting it, using R?
  • Word for a part of a book containing introduction and background/state of the art
  • How to address team member who excessively defers to me and is unwilling to give clear feedback
  • Opening emacs without the scratch buffer when opening a file (Please tell me what is wrong with my init file snippet)?
  • What famous meme am I referencing with a polynomial?
  • Why does the expectation value in quantum mechanics correspond to the classically measured value?
  • Interpreting TRS-80 model 1/2 tape cassette audio
  • What's a word for fake politeness?
  • The same material looks different
  • Why is triangle used instead of Quad?
  • Why does a MOSFET gate respond to voltage and not current?
  • Does killing an application kill the SQL connection?
  • Current-limited H-bridge
  • Can a single tympanal ear detect the direction or distance from which a sound comes?
  • Automated generation of homework questions for line problems
  • What's wrong with my joke 这位外科医生不礼貌,他总是说脏话, and how can I salvage it?
  • Can I get a late payment on my credit card if apr is 0% for the first 21 months?
  • Adding spaces to an apex class definition
  • Why is this seemingly slower C loop actually twice as fast as the other way?
  • When is it really worth it to convert RGB to CMYK (If printers do it anyway!)

more hot questions

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

How to generate auto increment number in php?

“auto increment number in php” Code Answer's.
$var = 0;.
// use value (0) THEN increment by one..
$var++;.
// increment by one THEN use value (1).
++$var;.
// aside: increment by custom amount (1 emulates the above).
$var += 1;.

How can generate invoice no in PHP?

Show activity on this post..
1 - 0000001 | 0000002 | 0000003 | 0000004 | 0000005. $dbValue = 1; echo $dbValue = str_pad($dbValue, 7, "0", STR_PAD_LEFT); // it will give 0000001;.
2 - F-0000001 | F-0000002 | F-0000003 | F-0000004 | F-0000005..

How do I generate an invoice number in SQL?

First create the table:.
CREATE TABLE [dbo].[controlFile](.
[number] [bigint] NULL..
) ON [PRIMARY].
create procedure NewNumber..
update controlfile set number = number + 1..
select number from controlfile..

Whats an invoice number?

An invoice number is a unique, sequential code that is systematically assigned to invoices. Invoice numbers are one of the most important aspects of invoicing as they ensure that income is properly documented for tax and accounting purposes. They also make it easier to track payments and manage overdue invoices.