Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. How to use 4 digit incremental serial number on mysql database using PHP on my form

How to use 4 digit incremental serial number on mysql database using PHP on my form

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasequestionphpmysqlhelp
3 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13659767
    wrote on last edited by
    #1

    Please I need help on how to use 4 digit format as incremental value using PHP. the cod below I used displays incremetally but it only in 1,2,3 instead of 001,002,003. What is wrong with m code?

    $query = "Select Max(Serial_Number) From captain_order";
    $returnD = mysql_query($query);
    $result = mysql_fetch_assoc($returnD);
    Print mysql_error();
    $maxRows = $result['Max(Serial_Number)'];
    if(empty($maxRows)){
    $lastRow = $maxRows = 1;
    }else{
    $lastRow = $maxRows + 0001 ;
    }

    J 1 Reply Last reply
    0
    • U User 13659767

      Please I need help on how to use 4 digit format as incremental value using PHP. the cod below I used displays incremetally but it only in 1,2,3 instead of 001,002,003. What is wrong with m code?

      $query = "Select Max(Serial_Number) From captain_order";
      $returnD = mysql_query($query);
      $result = mysql_fetch_assoc($returnD);
      Print mysql_error();
      $maxRows = $result['Max(Serial_Number)'];
      if(empty($maxRows)){
      $lastRow = $maxRows = 1;
      }else{
      $lastRow = $maxRows + 0001 ;
      }

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Computers don't know about leading zeroes. That is just a form of representing numbers to humans (being shown on screen, printed, or even written on a piece of paper). So just use

      $lastRow = $maxRows + 1;

      If you want to show the number with leading zeroes, use a corresponding formatting function like PHP: sprintf - Manual[^]:

      echo sprintf("%03d", $lastRow);

      U 1 Reply Last reply
      0
      • J Jochen Arndt

        Computers don't know about leading zeroes. That is just a form of representing numbers to humans (being shown on screen, printed, or even written on a piece of paper). So just use

        $lastRow = $maxRows + 1;

        If you want to show the number with leading zeroes, use a corresponding formatting function like PHP: sprintf - Manual[^]:

        echo sprintf("%03d", $lastRow);

        U Offline
        U Offline
        User 13659767
        wrote on last edited by
        #3

        Thanks Jochen.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups