Jump to content

Recommended Posts

Hi all,

 

I am having a problem with the below:

 

$remove = "SELECT credits FROM users_details WHERE credits > 9";
$result=mysql_query($remove) or die ("shit   " .mysql_error()) ;
			$rows = mysql_fetch_array($result);
			$credits = $rows['credits'];
			$m = 10;

			if ($credits > 9)
			{
				$nc = $credits - $m;
				$updatec = "UPDATE users_details SET credits=$nc";
	  
	    if (mysql_query($updatec))
{
      echo "Credits Removed<br />\n";
  }
  else {
  die(mysql_error());
  }

			}

 

Basically it is meant to remove 10 credits from any user that has above 10 credits. However instead it find the 1st user with more than 10, ie this user has 20 credits, it then changes every user with above 10 credits to only having 10 credits, regardless if the have 40 or 2000! How do I get around this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/180094-solved-more-phpmysql-woes/
Share on other sites

Basically it is meant to remove 10 credits from any user that has above 10 credits

This will update all records greater than 10 credits in one go. You do not require any loop (this is your current error, there is no loop. Only one record returned)!

UPDATE users_details SET credits = credits-10 WHERE credits > 10

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.