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

php mysql format question

  • 02-03-2007 10: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,631 ✭✭✭daymobrew


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


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭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