Jump to content

Zerofill In MySQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
BASHERS33

BASHERS33

    Programmer

  • Members
  • PipPipPipPip
  • 198 posts
Is there any issue which could happen if my query uses a value which was a result of intval() and in the DB the field has the zerofill attribute?

So far everything seems to work properly when the query uses 1 or 2 and the actual value in the DB is 0000000001 and 0000000002. But just checking to make sure.

Basically I used zerofill to make the numbers look better on the screen. But if I use intval() to make sure it's a number before querying then it strips the zeroes. If I do NOT use intval() then it may not be a number... I don't know if that could cause problems or not. I assume it would simply change the value to 0 and still not error out if I don't use intval() and it's not a number?

#2
BASHERS33

BASHERS33

    Programmer

  • Members
  • PipPipPipPip
  • 198 posts
I ams till curious about this, but I solved my problem by using is_numeric() to be sure it's a number since a zerofill fails is_int().

So I'm having all the zeroes still in the number. But I'm curious either way I guess.

#3
Drew

Drew

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
//Get value from the database as a string.
$valuestring = "".mysql_query("select value from table where conditions")
if ((int)$valuestring > 0) // Check if it's greater than 0 as an integer, but not change the actual value because it changes to an int as a temporary for the IF, then is a string still.
{
  //Do what you want to the string in here, it has all leading zeros still attached.
}