Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php mysql format question

  • 02-03-2007 9:40am
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    hi

    i have a field in my db called orderid

    if i pull a value from it for example 33 how do i format it with php to show
    00000033 ?

    Tnx


Comments

  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    something like ...

    str_pad("33", 10, "0", STR_PAD_LEFT);


    make yourself a little function and hey presto ...

    function pad0($number,$zeros="0")
    {
    return str_pad($number, $zeros, "0", STR_PAD_LEFT);
    }

    pad0("33",10);


  • Registered Users, Registered Users 2 Posts: 6,570 ✭✭✭daymobrew


    sprintf.
    $formatted_str = sprintf( '%08d', $num_from_db );
    


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    You can also tell MySQL to format the data when it selects it

    SELECT LPAD(`ID_Column`,8,'0') FROM TABLE....

    Will add the '0' character onto ID_Column, up to a maximum of 8 characters.


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


    you can also have this setup in your database start id 0000001


Advertisement