greencoin Posted June 19, 2007 Share Posted June 19, 2007 I'm trying to query the database, return the 5 digit ID + 1 and echo it into a text field. I have it all working but I'm losing my zeros! MySQL shows 00001 but my page displays 1. The ID is stored in MySQL as mediumint(5), unassigned zerofill. The php query is as follows; $query2 = mysql_query("SELECT MAX(iid+1) AS maximum FROM gc_prod_info") or die(mysql_error()); Do I need to change my query to SELECT MAX(iid+00001) ...? Any advice is appreciated. Thanks ~Rich Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/ Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 my sql consider 00001 as 1 so get 1 as an output all the zero at the left ignored. now to have the complete number of character use 10000 Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277301 Share on other sites More sharing options...
greencoin Posted June 19, 2007 Author Share Posted June 19, 2007 so are you saying that my numeric sequence has to start @ 10001 instead of 00001? ~Rich Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277598 Share on other sites More sharing options...
Illusion Posted June 19, 2007 Share Posted June 19, 2007 try this SELECT CAST(MAX(iid+1) AS VARCHAR) AS maximum FROM gc_prod_info or SELECT CAST(MAX(iid) AS VARCHAR)+1 AS maximum FROM gc_prod_info but I am not sure.............. Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277605 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2007 Share Posted June 19, 2007 Use either the function sprintf() to format the string or printf() to print a formated string with a zero filled field. <?php $i = 1; printf("%05d",$i); ?> Ken Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277625 Share on other sites More sharing options...
greencoin Posted June 19, 2007 Author Share Posted June 19, 2007 try this SELECT CAST(MAX(iid+1) AS VARCHAR) AS maximum FROM gc_prod_info or SELECT CAST(MAX(iid) AS VARCHAR)+1 AS maximum FROM gc_prod_info but I am not sure.............. I'm not sure changing it to a VARCHAR will work as I'm pushing it back into MySQL as an INT when the form is submitted... ~Rich Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277653 Share on other sites More sharing options...
Illusion Posted June 19, 2007 Share Posted June 19, 2007 I'm not sure changing it to a VARCHAR will work as I'm pushing it back into MySQL as an INT when the form is submitted... ~Rich You can submit it as an INT, no problem. Link to comment https://forums.phpfreaks.com/topic/56136-mysql-shows-5-digit-id-00001-using-zerofill-php-query-displays-1-digit-1/#findComment-277663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.