Jump to content

If Statement order not working


IndianaGuy

Recommended Posts

I am utterly confused with this. The Section 1 works fine but section 2 says"  could not find section 2 info".

If I copy/paste section 2 on top of section 1, then section 2 will work and section 1 will say "could not find section 1 info" !!!  Something happens after a SECTION that makes it stop recognizing the following section. Thank you for your advice.

	$sql3 = "SELECT * FROM tbl_imd WHERE memberid_fk = '$ses_memberID'";
$result = mysqli_query($conn, $sql3);
	if (mysqli_num_rows($result) > 0) {
    // profile already started so display content
    //echo "profile in the system";
    
    while($row = mysqli_fetch_array($result)) {
        echo "Basic information:<hr>";
        echo "Member ID: ACTIVE<BR>";    
        echo "Name: " . $row['full_name']. "<br>";
        echo "Email: " . $row['email']. "<br>";
        echo "Phone: " . $row['phone']. "<br>"; 
        echo "IMD#: " . $row['imd_num']. "<br>";    
        echo "From: " . $row['city']. ", " .$row['state']. "<br>"; 
        echo "Background: " . $row['background']. "<br>";
	/**********************SECTION 1**************************/
            if ($row['upline_pri']=="0"){
                $upline_pri = "not selected";
                echo "Primary upline: " . $upline_pri . "<br>";    
        
            }
            
             if ($row['upline_pri']!="0"){
                $upline_pri = $row['upline_pri'];
                //echo "<br> upline pri = " . $upline_pri;
            
                $sql4 = "SELECT full_name FROM tbl_imd WHERE imd_pk = '$upline_pri'";
                $result = mysqli_query($conn, $sql4);
	                    if (mysqli_num_rows($result) > 0) {
                        while($row = mysqli_fetch_array($result)) {    
                        echo "Primary Upline: "  . $row['full_name']. "<br>"; 
                            
                        }
                    } else {
                     echo "Could not find section 1 info";
                    }  
            } 
        
        
     /****************************SECTION 2***************************/        
        //echo $row['upline_bak'];
        echo "1 <br>";
	        
        if ($row['upline_bak']=="0"){
            $upline_bak = "not selected";
            echo "Backup upline: " . $upline_bak . "<br>";    
        echo "2 <br>";
        }
        
        if ($row['upline_bak']!="0"){
            $upline_bak = $row['upline_bak'];
            //echo "<br> upline pri = " . $upline_pri;
            echo "3 <br>";
            $sql4= "SELECT full_name FROM tbl_imd WHERE imd_pk = '$upline_bak'";
            $result1 = mysqli_query($conn, $sql4);
echo "4 <br>";
                if (mysqli_num_rows($result1) > 0) {
                    while($row = mysqli_fetch_array($result)) {    
                        echo "Backup upline: "  . $row['full_name']. "<br>";  
                        echo "5 <br>";
                    }
                 } else {
                     echo "Could not find section 2 info";
                 }
        } 
	    
	    }
} else {
    echo "ERROR: SELECT * FROM tbl_imd WHERE memberid_fk = ses_memberID ";
}
	
                    
	mysqli_close($conn);
?>
	

Link to comment
Share on other sites

I am trying this. the console shows the right value,  but when it gets send to accessName.php, it comes back saying it's not there. I tested accessName.php alone by setting $name="24" and I get the results I want. The 24 is the same value of the console log

	 <script>
$(document).ready(function(){
$("#btn").click(function(){
var vname = $("#uplinePri").text();
console.log(vname);
if(vname=='' )
{
alert("vname is empty");
}
	else{
    
 console.log(vname);   
$.post("accessName.php",
{ 
name:vname
},
	function(response){ 
$("#uplinePri").text(response);
});
}
});
});
</script>
	
Edited by IndianaGuy
code fix
Link to comment
Share on other sites

No, it doesn't have anything to do with ajax.  You just keep using the same variable name, so it overwrites the first.  You loop over the result from $sql4 using $row, and then in section 2 you're trying to check $row again assuming it's from $sql3, but you overwrote it in the other loop.  Just use different variable names, don't call everything $result or $row.  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...