Jump to content

** FIXED ** Pulling an Integer From MySQL and testing it


JustinK101

Recommended Posts

Hello I have the following function:

[code]
function isnull($input) {
if((is_int($input)) && ($input == 0))
{
return 0;
}
else if(empty($input) || $input == "00/00/0000")
{
return ('---');
}
else
{
return ($input);
}
}
[/code]

I am passing two variables that are stored $row via mysql. The two values are stored in mysql as int(10) and smallint(2). So it looks like:

[code]
while($row = mysql_fetch_array())
{
  isnull($row[0]);
  isnull($row[1]);
}
[/code]

The problem is that isnull() is returning '---' instead of 0 for my integer values that are zeroed. Any idea why?
[quote author=JustinK101 link=topic=113641.msg461904#msg461904 date=1162495270]

The problem is that isnull() is returning '---' instead of 0 for my integer values that are zeroed. Any idea why?
[/quote]

Before I procceed, just curious what array you're fetching in:

[code]
while($row = mysql_fetch_array())
{
  isnull($row[0]);
  isnull($row[1]);
}
[/code]

And wondering if you purposely left that out.
Sorry I just wrote that code, should be:

while($row = mysql_fetch_array($result))
{
    isnull($row[0]);  //SHOULD BE RETURNING 0, BUT ITS RETURNING ---
    isnull($row[1]);  //SHOULD BE RETURNING 0, BUT ITS RETURNING ---

}
I have confirmed though, it is treating the mysql values which is a int as a string. Humm, why? Any way to explicitly make it an int? I have swore I have pulled ints from mysql and done addition, subtracting on them before without having to cast.

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.