|
|
|
|
![]() ![]() |
Dec 20 2006, 09:16 PM
Post
#1
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 17-May 06 Member No.: 23,815 |
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: CODE // 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: [code][/code] aka, nothing. NULL. It's like I'm trying to add something to a string :/ Any ideas? Thanks, -E |
|
|
|
Dec 20 2006, 11:45 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,083 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Untested.
CODE $new += $row['logins']; Or: CODE $new = $row['logins'] + 1; |
|
|
|
Dec 20 2006, 11:49 PM
Post
#3
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 17-May 06 Member No.: 23,815 |
yeh... it worked after 5 refreshes, for some reason :/
but now it won't update... CODE $query ="UPDATE users SET logins='$new' WHERE id='$id'"; // echo $id returns the correct number. ? -E |
|
|
|
Dec 20 2006, 11:50 PM
Post
#4
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 181 Joined: 22-February 06 Member No.: 19,007 |
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
CODE 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 |
|
|
|
Dec 20 2006, 11:55 PM
Post
#5
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,083 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Good catch, Midnitesun.
|
|
|
|
Dec 20 2006, 11:59 PM
Post
#6
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 17-May 06 Member No.: 23,815 |
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 |
|
|
|
Dec 22 2006, 05:45 PM
Post
#7
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 162 Joined: 10-May 06 Member No.: 23,375 |
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 |
|
|
|
Dec 22 2006, 05:51 PM
Post
#8
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 17-May 06 Member No.: 23,815 |
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 |
|
|
|
![]() ![]() |
Similar Topics