IndianaGuy Posted November 10, 2017 Share Posted November 10, 2017 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 More sharing options...
justsomeguy Posted November 10, 2017 Share Posted November 10, 2017 You keep overwriting $row. Link to comment Share on other sites More sharing options...
IndianaGuy Posted November 10, 2017 Author Share Posted November 10, 2017 Hmmmm! You mean in the "while..." statement?. That's interesting and thank you. How would I go about overcoming that?. Will it be better if I use Ajax to get the information i need based on the $row['value1'] and $row['value2']? Link to comment Share on other sites More sharing options...
IndianaGuy Posted November 10, 2017 Author Share Posted November 10, 2017 (edited) 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 November 10, 2017 by IndianaGuy code fix Link to comment Share on other sites More sharing options...
justsomeguy Posted November 10, 2017 Share Posted November 10, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now