0

I have this code:

$showCountSql    = "select cad_count from counteraccountdtl WHERE cad_userid =".$_SESSION['UID']." LIMIT 1";
$showCountresult = mysql_query($showCountSql);
$showCountrow    = mysql_fetch_array($showCountresult);
$newCount        = $showCountrow[cad_count];

if(is_int($newCount))
 echo "Value  is Integer";
else
 echo "Value not Integer";

I am fetching the value from MySql as "cad_count integer(5)", then I check whether this value is an integer or not and show the "Value not Integer" accordingly. What's wrong in it?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Manoj Patil
  • 35
  • 1
  • 1
  • 9
  • You can always use `var_dump($newCount)` to see exactly what the variable's type is, along with contents. – Marc B Sep 12 '11 at 15:14
  • For completness to the answers, `mysql_fetch_array` returns an array of strings. See docs: http://www.php.net/manual/en/function.mysql-fetch-array.php – enricog Sep 12 '11 at 15:22

2 Answers2

2

Use is_numeric() or ctype_digit(). These functions test if the given variable is a valid representation of a number or contains only digits.

is_int tests if the variable's type is int, and mysql_fetch* functions return integers as strings.

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
0

is_numeric() is better for you. To make is_int() work, you have to make int value from old one

$var = intval($var);
genesis
  • 50,477
  • 20
  • 96
  • 125