JustinK101 Posted November 2, 2006 Share Posted November 2, 2006 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? Link to comment https://forums.phpfreaks.com/topic/25969-fixed-pulling-an-integer-from-mysql-and-testing-it/ Share on other sites More sharing options...
Caesar Posted November 2, 2006 Share Posted November 2, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/25969-fixed-pulling-an-integer-from-mysql-and-testing-it/#findComment-118710 Share on other sites More sharing options...
JustinK101 Posted November 2, 2006 Author Share Posted November 2, 2006 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 ---} Link to comment https://forums.phpfreaks.com/topic/25969-fixed-pulling-an-integer-from-mysql-and-testing-it/#findComment-118743 Share on other sites More sharing options...
JustinK101 Posted November 2, 2006 Author Share Posted November 2, 2006 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. Link to comment https://forums.phpfreaks.com/topic/25969-fixed-pulling-an-integer-from-mysql-and-testing-it/#findComment-118744 Share on other sites More sharing options...
JustinK101 Posted November 2, 2006 Author Share Posted November 2, 2006 FIXED it, I have to cast explicity:isnull((int)$row[0]);isnull((int)$row[1]); Link to comment https://forums.phpfreaks.com/topic/25969-fixed-pulling-an-integer-from-mysql-and-testing-it/#findComment-118751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.