PHP generates employee number, product number

Source: Internet
Author: User

For some reason, you need to get the database's maximum ID value. So the PHP gets the largest ID code for the database. The ID inside of this is the maximum ID to get. If it is another field please fill in the other fields

Gets the value of the largest ID in the database

$fh = mysql_query ("Select MAX (ID) from master");
$c _echo = mysql_fetch_array ($FH);
Var_dump ($c _echo);

Then get the employee number

$str = "QB". Str_pad (($maxid [0]["Max (ID)"]+1), 5, "0″,str_pad_left");

The Str_pad () function fills a string with the specified length.

Grammar Str_pad The (string, length,pad_string,pad_type) parameter     describes the string      required. Specifies the string to populate. Length     required. Specifies the length of the new string. If the value is less than the length of the original string, no action is made. Pad_string     is optional. Specifies the string to use for padding. The default is blank. Pad_type     is optional. Specify the padding string over there. Possible values:    str_pad_both– are populated to both ends of the string. If it is not an even number, the right side gets an extra fill.    str_pad_left– fills the left side of the string.    The str_pad_right– is populated to the right of the string. This is the default. 

This completes the product, the employees are tried

PHP generates employee number, product number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.