Reply to Re: LAST_INSERT_ID with ZEROFILL

Your name:

Reply:


Posted by Kelsey Sigurdur on 10/19/07 01:19

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($insertQuery);
> if($result)
> {
> //$uniqueFilenameResult = mysql_insert_id($link).$uploadFilename;
> $insertIDResult = mysql_query("SELECT LAST_INSERT_ID()");
> if($insertIDResult)
> {
> $nrows = mysql_num_rows($insertIDResult);
> $rows = mysql_fetch_row($insertIDResult);
> $uniqueFilenameResult = $rows[0].$filename;
> }
> }

You can use str_pad() to fill it back out.

$insertIDResult = mysql_query("SELECT LAST_INSERT_ID()");
$insertIDResult = str_pad($insertIDResult, N, "0", STR_PAD_LEFT);

Where N is the desired length of the string.

--
Kelsey Sigurdur

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация