473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formatting intergers in php

274 100+
hi,
I have setup a query to insert datab in the databse and then display the ID(an auto increment primary key) of the record on the screen. ID type is bigint and it works fine all the way I want it. My question is I want to display like this
Assigned ID: QUT-0000000001
where as appears as follows:
Assigned ID: QUT-1
What I can do to do that?
1 is the id that I got from database. Sounds like it is easy to do it but I can't find any example. I do see some for fractional values.
Thanks in advance.
Oct 27 '08 #1
2 1181
Atli
5,058 Expert 4TB
If this database is using MySQL, then you could simply add the ZEROFILL parameter to your column. That would automatically pad the value with zeros.

For example, this table:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `tbl`( 
  2.   ID Int(5) Zerofill
  3. );
  4.  
Populated with the numbers 1, 12 and 123 would return the following data:
Expand|Select|Wrap|Line Numbers
  1. 00001
  2. 00012
  3. 00123
  4.  
If you are not using MySQL, or would rather do this in PHP, you could use the str_pad function in PHP.
Like, for example:
Expand|Select|Wrap|Line Numbers
  1. echo str_pad(1, 5, "0", STR_PAD_LEFT);
  2.  
Which should output: 00001
Oct 27 '08 #2
creative1
274 100+
Thanks a lot,
It helped,
Regards,
C
Oct 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
11
by: Taorluath | last post by:
ok, so this little script is supposed to list the factors of intergers. <?php function findfacts($x) { $highest = $x; $counter = 1; $factarray;
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.