I want to retrieve selected records in my list.For example I have table advisor and partcipant, i want produce a list of participant that are registered under Advisor A.But when I write this sql statement, it display all participant records in the database.Can someone help me solve this problem? $sql="SELECT * FROM advisor WHERE Advisor_id='$Advisor_id'"; Code (markup):
1) Is the field Advisor_id numeric or character? 2) What's the value of $Advisor_id when this line executes? 3) Is participant one of the fields in the table advisor?
1)Advisor_id is character because it can be either user identification number/passport number. 2)The value of advisor_id was the same as in the table.*Is this the answer you looking for?because i got a little confused with the question 3)No.but advisor is one of the field in participant table. I hope you can help me solve this.Thank You
Okay. No. What is the value, at the time the script is running, of the variable $Advisor_id? You'll have to use whatever you use for debugging to show you the value at the time that line of code is executed. If you don't use anything to debug (in which case you aren't yet at the level at which you should be writing any PHP code), you can use $sql="SELECT * FROM advisor WHERE Advisor_id='$Advisor_id'"; echo '<br />'.$sql; exit; PHP: temporarily, to see what your query looks like. Your query and your stated intent aren't the same, then. You should use a JOIN to get the participants in table participant that have advisor $Advisor_id in table advisor.
How to use the right JOIN statement.Because I tried it and still failed. This is what I got when I run that sql.
Then you're never setting $Advisor_id equal to anything. A variable doesn't exist in PHP until you make it be something - have it on the left side of the equal sign, as: $Advisor_id = <some value here>;