SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow do you see problem with this if elseif statement?

    ok

    i have these codes below.
    Code:
    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.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try once with !==
    PHP Code:
    if($link !== $jtablegrid_link){
    ....

    Edit:
    BTW what are the possible values that may come with those both of the variables $link and $jtablegrid_link?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the condition is not working as expected, then inspect the condition and find out why.

    var_dump() the variables.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •