Jump to content

[SOLVED] do you see problem with this if elseif statement?


ok

Recommended Posts

ok

 

i have these codes below.

if($link!=$jtablegrid_link) {	//this condition will limit the player from accidentally clicking the already taken number
if($user_click<50) {
	//if user has tickets equal or greater than 1
		if($balance_jackpot>=1 || $balance>=1) {
			//check record existence first before writing.
			$strQuery1 = "select count(*) as cnt from jtablegrid where box_no='".$link."'";
			$res = mysql_query($strQuery1);
			$row = mysql_fetch_array($res);
			$intCount = $row['cnt'];

			if($intCount == 0) {
			  $query = "INSERT INTO jtablegrid (username, box_no) VALUES ('$username','.$link.')"; 
			  mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
			}

			//this will subtract balance and balance_jackpot.
			//everytime a user click it subtract 1 ticket from balance_jackpot column or from balance.			
			if($balance_jackpot>=1) {
				$jackpot_subtracted = $balance_jackpot-1;

				//then update user table.
				$query = "UPDATE user SET balance_jackpot='$jackpot_subtracted' WHERE username='$username'"; 
				mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
			} elseif($balance>=1) {
				#$balance_original = $balance;
				#$balance = floor($balance); //round down.
				if($balance>=1){
					$balance_tmp = $balance-1;

					//then update user table.
					$query = "UPDATE user SET balance='$balance_tmp' WHERE username='$username'";
					mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
				}		
			}
		} else {
			echo "<br><br>";
			echo "<b>Sorry, you don't have enough ticket.</b>";
			echo "<br><br>";		
		}
} else {
        echo "<br><br>";
        echo "<b>You already reached the 50 click user limit per game.</b><br>";
        echo "<b>Please wait for the next game, Thank you!</b>";			
        echo "<br><br>";		
}
} elseif($link==$jtablegrid_link) {
echo "<br><br>";
echo "<b>That number is already taken.</b>";
echo "<br><br>";		
}

 

what really bother me is when this if below is false

if($link!=$jtablegrid_link)

 

it still execute the other if inside it.

what do you think is a nice remedy for this?

or do you see bugs on my if elseif statements?

 

Thank you in advance.

 

 

Syntactically, everything looks fine. I will say that your elseif statement is completely redundant though.

 

if($link!=$jtablegrid_link)
// ...
elseif($link==$jtablegrid_link)

 

...are always the inverse of each other. So if $link is not equal to $jtablegrid_link, than $link most certainly DOES equal $jtablegrid_link. All you need is an else statement.

 

It would seem that the problems you are experiencing occur at or after the line:

if($user_click<50) {

Perhaps you can explain how that code is not working.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.