Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2004, 11:55 AM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default MySQL return a String instead of an INT

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
__________________
Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 2nd, 2004, 10:50 AM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Anyone???

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 2nd, 2004, 01:23 PM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Please note, I have solved this issue.

My problem was only partially the STRING instead of INT. I did use the INTVAL() function to return an INT. I would then try and, for debugging, echo out the value and type. However, I was using the DIE() function (to halt execution at that point).

Apparently, that was part of the problem. The integer (in variable form) in the DIE function would not echo.

Then to add to it, I had a Malformed FOR () statement causing further problems.

Suffice it to say... I did manage to solve the problem.


Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to return string value with quotes (single or tllcll BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 November 10th, 2005 01:57 PM
Return ASCII values for a given string sal C# 1 May 19th, 2005 03:59 PM
return next full int Mantis Pro PHP 1 April 14th, 2005 09:16 AM
Converting int to string Judex C++ Programming 3 March 1st, 2004 10:44 AM
Return String is Different kochoo Classic ASP Components 2 October 19th, 2003 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.