Ok... I am trying to get a value from my database which is an INT(11) type field. My code (snipit) is as follows:
$transid='4372511011';
$sql= "SELECT status_id FROM trans_status WHERE trans_id =$transid";
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
$status = $data[0];
$status+= 1;
The
status_id field is, as stated above, an INT(11) field in the database.
My problem lies that when I fetch the data and assign it to the $status variable it will not assign it as an INT but as a STRING. Thus the MATH on it is not performed.
Now, I was under the impression that PHP (generally) does not require the type to be explicitly declared, however, I have tried that. The result is that the STRING (from the query) doesn't get assined. I have also tried intval() but it retuns either a NULL or an INT. If I get it to return as an INT, I can do no math functions on it.
i.e.
$transid='4372511011';
$sql= "SELECT status_id FROM trans_status WHERE trans_id =$transid";
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
$status = intval($data[0]); // assigns value as an INT
echo $status.'<br>'; // Will echo the value assigned
$status = $status +1 ; // Should (ideally) ADD 1 to the value
echo $status; // Should echo $status incremented by one but instead echos NOTHING
So what am I doing wrong? Any help is GREATLY appreciated.
Paul Gardner
------------------
PHP-LIVE help
Via Web @
http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP