Jump to content

'where and or' help needed


APuppyDog

Recommended Posts

i have a piece of code which subtracts credits every time a button is clicked. the original code works fine. I have since added a bonus_credit column, where i want it to function like this. if buy_credit = 0 and bonus_credit>0 then subtract from the bonus credit, but still do everything else its supposed to do..

 

here is the original code i had

	$selRes=mysql_query("SELECT buy_credit from user where id='".$hb_id."' and buy_credit>0");
if(mysql_affected_rows()>0)
{
	$b_comm=0;
	$bc_updqry=mysql_query("UPDATE user set buy_credit=buy_credit-1 where id='".$hb_id."'");
	$updqry=mysql_query("UPDATE cars set b_fee_paid_status='1' where id='".$aid."'");
}

 

here is my modified code, but it doesn't seem to subtract from buy_credit if buy_credit is >0.. it should only kick in the bonus_credit usage if buy_credit is 0

	$selRes=mysql_query("SELECT buy_credit,bonus_credit from user where id='".$hb_id."' and buy_credit>0 OR bonus_credit>0");
if(mysql_affected_rows()>0)
{
	$b_comm=0;
		if($selRes['buy_credit']!=0)
		{
		$bc_updqry=mysql_query("UPDATE user set buy_credit=buy_credit-1 where id='".$hb_id."'");
		}
		else {
			$bc_updqry=mysql_query("UPDATE user set bonus_credit=bonus_credit-1 where id='".$hb_id."'");
			}
	$updqry=mysql_query("UPDATE cars set b_fee_paid_status='1' where id='".$aid."'");
}

 

your help is appreciated.

Link to comment
Share on other sites

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.