Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

simple php/mysql questions

  • 21-07-2009 12:02PM
    #1
    Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭


    When injecting an integer like 0024, mysql or perhaps php omitts the first two 0's and enters 24,
    tried using varchar/text, no luck.


Comments

  • Registered Users, Registered Users 2 Posts: 9,228 ✭✭✭Chardee MacDennis


    just cast it as a string first...


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    or if you printing and it will always be 4 digits:

    [php]printf("The number is %04d", 24);[/php]

    But it looks like you mean when storing in a DB. Having 0's before an integer has no meaning to an integer type so they are ommitted. As above, use a char/string instead.


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    doesnt work ? varchar data type...

    tried


    $code1 = "$code[0]";

    and

    $code1 = (string)$code[0];

    //its an array value.




    Just gonna use zerofill in type INT, and limit it to 4, so 24 will be 0024, this field will always be 4 digits max so it works out
    but not sure why other stuff didnt work, annoying...


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    str_pad_left ?


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    set the field as "varchar. int or numeric will remove the 0


  • Advertisement
Advertisement