This is for a self test for a college job application so I am not necessarily looking for the exact statement I need, instead I am trying to get a hint as to what direction to look, I DO NOT have access to the actual database to view it:
This problem tasks us with using JOIN to select data about users from one table based on if they have a hold on their account on another table, the problem also ONLY wants students in the College that is given by the $college argument.
I am pretty new to PHP so I've been using w3schools as a guide and I have used their INNER JOIN example exactly, yet it keeps giving me a 'unknown column E(or any other letter given by $college) in 'where clause'', or if I change the "" to '' it changes to 'unknown column $college in 'where clause''
Here is my code:
<?php
function hasHold($college)
{
$query = "SELECT interview_student.Student_ID,
interview_student.Last_Name,
interview_student.First_Name,
interview_student.College,
interview_account_hold.Amount_Due
FROM interview_student INNER JOIN interview_account_hold
ON interview_student.Student_ID = interview_account_hold.Student_ID
WHERE interview_student.College = $college";
return $query;
}
?>
Assuming access to the interview_student table from the previous question...
+------------------------------------------------------+
| interview_student |
+------------+-----------+------------+---------+------+
| Student_ID | Last_Name | First_Name | College | GPA |
+------------+-----------+------------+---------+------+
| 463127376 | Willemsen | Lucas | A | 2.37 |
+------------+-----------+------------+---------+------+
The accounting office has provided us a list of students who currently have holds on their accounts because of unpaid tuition. They are only listed by ID and amount due; and they are only listed if they have an amount due. Students who have no amount due are not listed.
+-------------------------+
| interview_account_hold |
+-------------------------+
| Student_ID | Amount_Due |
+------------+------------+
| 416996983 | 3,403.20 |
| 287856417 | 2,318.13 |
| 537713123 | 3,678.06 |
| 187296716 | 2,202.83 |
| 145768187 | 2,379.32 |
+------------+------------+
Write a function called hasHold that takes one argument ($college) and returns a string (a SELECT statement).
The argument passed to the function will be a college code (such as 'A' for Agriculture).
The string returned should be a SELECT statement that will return all the students who are in the given college that have an account hold in place. The resulting query should return the following fields in the following order: Student ID, Last Name, First Name, College, Amount Due.
Once again, the function should return the SELECT statement as a string. You do not need to handle the actual connection, submitting the query, parsing the results, etc. Just return a string.