Jump to content

mysql shows 5 digit ID; 00001 using zerofill, php query displays 1 digit; 1


greencoin

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.