In php the str_pad function is used to generate the product number in numeric increments

  • 2020-10-23 20:03:41
  • OfStack

Solution: $str QB. "=" str_pad (($maxid [0] [" max (id) "] + 1), 5, "0", STR_PAD_LEFT);

Where $maxid[0]["max(id)"]+1) is to use the max function to find the largest value of ID from the database. ID is the primary key and does not repeat.

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

grammar

str_pad(string,length,pad_string,pad_type) parameter describe string A necessity. Specifies the string to be filled. length A necessity. Specifies the length of the new string. If the value is less than the length of the original string, nothing is done. pad_string Optional. Specifies a string to use for padding. The default is blank. pad_type Optional. Specify the side of the fill string. Possible values:

STR_PAD_BOTH - Populate both ends of the string. If it is not even, the right side gets extra padding. The STR_PAD_LEFT wok is populated to the left of the string. STR_PAD_RIGHT fills to the right of the string. This is the default.


Related articles: