473,766 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LAST_INSERT_ID with ZEROFILL

I am losing the leading zeros when I get autoincrement IDs from a
column with ZEROFILL enabled. I would like to have the leading
zeros. I have tried both the php function last_insert_id as well as
running a SELECT query and using the result. I am getting the correct
id, it is just losing the leading zeros. I have doulbe checked the
table in the database, and it does have the leading zeros. Thanks for
any help.

$result = mysql_query($in sertQuery);
if($result)
{
//$uniqueFilename Result = mysql_insert_id ($link).$upload Filename;
$insertIDResult = mysql_query("SE LECT LAST_INSERT_ID( )");
if($insertIDRes ult)
{
$nrows = mysql_num_rows( $insertIDResult );
$rows = mysql_fetch_row ($insertIDResul t);
$uniqueFilename Result = $rows[0].$filename;
}
}

Oct 18 '07 #1
2 2968
..oO(WebSnozz)
>I am losing the leading zeros when I get autoincrement IDs from a
column with ZEROFILL enabled.
I wouldn't rely on that.
>I would like to have the leading
zeros. I have tried both the php function last_insert_id as well as
running a SELECT query and using the result. I am getting the correct
id, it is just losing the leading zeros. I have doulbe checked the
table in the database, and it does have the leading zeros. Thanks for
any help.
Just store normal integers and add the leading zeros when you really
need them, for example with sprintf() in your script

Micha
Oct 18 '07 #2
On Thu, 18 Oct 2007 18:45:25 +0000, WebSnozz wrote:
I am losing the leading zeros when I get autoincrement IDs from a
column with ZEROFILL enabled. I would like to have the leading
zeros. I have tried both the php function last_insert_id as well as
running a SELECT query and using the result. I am getting the correct
id, it is just losing the leading zeros. I have doulbe checked the
table in the database, and it does have the leading zeros. Thanks for
any help.

$result = mysql_query($in sertQuery);
if($result)
{
//$uniqueFilename Result = mysql_insert_id ($link).$upload Filename;
$insertIDResult = mysql_query("SE LECT LAST_INSERT_ID( )");
if($insertIDRes ult)
{
$nrows = mysql_num_rows( $insertIDResult );
$rows = mysql_fetch_row ($insertIDResul t);
$uniqueFilename Result = $rows[0].$filename;
}
}
You can use str_pad() to fill it back out.

$insertIDResult = mysql_query("SE LECT LAST_INSERT_ID( )");
$insertIDResult = str_pad($insert IDResult, N, "0", STR_PAD_LEFT);

Where N is the desired length of the string.

--
Kelsey Sigurdur

Oct 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7328
by: Irene Mettias | last post by:
Hello, I've just installed perl DBI v1.38 which according to the documentation supports the method last_insert_id(). For some reason the return value I get is undef. Here is my source code : #!/usr/local/bin/perl
1
4274
by: Michal Adamczakk | last post by:
hi, how to implement mysql's last_insert_id() ? i know that seqences and oids are great. the one thing i miss is that they are not session specific. i mean selecting last_value from seqence can give me a value which was inserted by a different user.
6
12671
by: jim | last post by:
Hi, I have a site with various parts which allow users to enter info via forms which gets entered into various tables in a MySQL db (I'm using ASP, rather than PHP). I have an ecards bit, and when users send a card, their data is entered into the db via something like: INSERT vars into ecard_tbl....
3
19214
by: Khazret Sapenov | last post by:
Hi, What is the practical use of ZEROFILL in your case? regards, Khaz
3
41663
by: Vic Spainhower | last post by:
Hello, I am trying to get the value of the Auto-Incremented key that was assigned using LAST_INSERT_ID(). However, when I execute the following PHP statements after the insert I only get: "value of entryID: Resource id #7" after EVERY insert (it never changes). What am I doing wrong? Thanks very much!
2
2401
by: NotVeryBright | last post by:
Hello I'm trying to create a table as below CREATE TABLE MyTable (ID FLOAT NOT NULL PRIMARY KEY ZEROFILL, Forename VARCHAR(30),Surname VARCHAR(30)); If I remove ZEROFILL it works ok But with ZEROFILL I get and error (1064) I've tried ZEROFILL in different places and I'm stumped. Please help Best regards and thanks in advance
1
4122
by: simbarashe | last post by:
I am trying to insert an auto_increment value into multiple tables but its seems to lose its value after the the second insert statement and my code is as follows can any1 please help. The auto_increment value that i want to use is the one from the client table and it will insert in the CONTACTS table but it will not in the JOBSHEET and KNOWLEDGE table. last_insert_id() has not worked because i have auto increment fields in all the tables pliz...
3
2983
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it imiedietely after i insert value into session1... is there any other way to do it? insert into 2 tables at the same time ...? if(!($sessid)){ session_register('sessid'); mysql_query("insert into session1 set sessid=null,
1
3016
by: sonia.sardana | last post by:
Hi frnds, I want to know that zerofill is a valid function in SQL or not....
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.