Jump to content
xisto Community
elrohir

Incrementing Mysql Integer int comes out as string?

Recommended Posts

I am attempting to perform mathematical operations on a number extracted from a MySQL database. The integer is stored as an integer in the database, and nothing I am doing to it in the PHP script would transform it into a floating-point value.
I don't even want to worry about sticking it back in just yet:

// the value I want to increase here is logins... $query1 = "SELECT * FROM users WHERE id='$id'";$result1 = mysql_query($query1) or die(mysql_error());$row1 = mysql_fetch_array($result1);$new = $row['logins'] ++;echo $new;

returns:



aka, nothing. NULL.

It's like I'm trying to add something to a string :/ Any ideas?

Thanks,
-E

Share this post


Link to post
Share on other sites

now i am really confused , from where is $row coming ? you have given $row1 as the mysql fetch array so the code should i believe be $row1['logins'] instead of $row['logins'] , it seems you are trying to display all logins as an array , so if i am correct you can use

while $row1 = mysql_fetch_array($result1) {$new = $row1['logins'];echo $new;}

also try avoiding numbers in your code, it can be confusing both for you and your code

Share this post


Link to post
Share on other sites

Well you mentioned you wantd to try to convert it to float.To do that just put '(float)' in front of the Variable.You can even convert it to a string using (string).Also instead of using numbers in variables use arrays as that can simplify the whole process and there are many functions in PHP that are useful to be applied to arrays.Hope this helps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.