elrohir 0 Report post Posted December 20, 2006 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
jlhaslip 4 Report post Posted December 20, 2006 Untested. $new += $row['logins'];Or:$new = $row['logins'] + 1; Share this post Link to post Share on other sites
elrohir 0 Report post Posted December 20, 2006 yeh... it worked after 5 refreshes, for some reason :/but now it won't update... $query ="UPDATE users SET logins='$new' WHERE id='$id'";// echo $id returns the correct number. ?-E Share this post Link to post Share on other sites
midnitesun 0 Report post Posted December 20, 2006 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
jlhaslip 4 Report post Posted December 20, 2006 Good catch, Midnitesun. Share this post Link to post Share on other sites
elrohir 0 Report post Posted December 20, 2006 that should do the trick... -.- would have thought that it would not matter if there was only one record matching the WHERE...I'll give that a go Share this post Link to post Share on other sites
electron 0 Report post Posted December 22, 2006 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
elrohir 0 Report post Posted December 22, 2006 well, it wasn't exacly the most important number, so I just set the default in the database to 1 instead. I think it considered it 0 as in NULL, cause that solved it thanks anyways Share this post Link to post Share on other sites