bongo13 Posted April 9, 2006 Share Posted April 9, 2006 well, heres my script<?$query = "select * from users where user_username = '$username'";$result = mysql_query($query);while ($row = mysql_fetch_array($result)) {$old_points = $row['user_points'];}$points = $old_points - 1000;$query = "UPDATE users SET user_points = '$points' WHERE user_username = '$user_name'";$result = mysql_query($query); ?>1.it sets the users points to -1000 when i want it to take away - 1000 from the original points2. the variable $query is set before in the script, i tried putting $query1 in but it didnt make a differenceif you need any more information just post it and i'll see what i can do while you see what you can do. Link to comment https://forums.phpfreaks.com/topic/6919-set-to-1000/ Share on other sites More sharing options...
IceHawk Posted April 9, 2006 Share Posted April 9, 2006 May I recomend the below method instead;[code]$query = "select user_points from users where user_username = '$username'";$result = mysql_query($query);list($old_points) = mysql_fetch_row($result);$points = $old_points - 1000;$query = "UPDATE users SET user_points = '$points' WHERE user_username = '$user_name'";$result = mysql_query($query);[/code]Replacing the needless while loop with list($old_points) = mysql_fetch_row($result) saves some lines. And specifying in the query to only select the column you're working with will save time on the query as well.A possible cause of your error I see is that in the first query you use $username, but in the update you use $user_name. Not sure which one holds the actual username you're using though, but you will want to double check that. Link to comment https://forums.phpfreaks.com/topic/6919-set-to-1000/#findComment-25134 Share on other sites More sharing options...
akitchin Posted April 9, 2006 Share Posted April 9, 2006 to avoid the whole issue, reference the original value itself:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] users SET user_points [color=orange]=[/color] user_points [color=orange]-[/color] 1000 [color=green]WHERE[/color] blah blah blah [!--sql2--][/div][!--sql3--]you don't have to waste resources by grabbing it in the first place. mysql already knows the original value. Link to comment https://forums.phpfreaks.com/topic/6919-set-to-1000/#findComment-25160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.