I've looked at several other entries for how to use an array in a WHERE clause but I couldn't find the right solution for me. What I am trying to do is to create a drop down menu with dynamic values based on a Recordset containing $_SESSION variables.
What I want it to do is to list the possible classes in a drop down menu that a specific teacher is able to teach (so the list is dependant on what teacher is logged into the system). All the session variables needed work perfectly fine in itself, and as long as the session variables I put in my queries are single result strings there's no fault at all. But once I am encountering an array in my variables, that's where it's going wrong on me.
I read on other posts that in order to use an array in a WHERE clause, I have to create a function to convert the array into a string, as I've done below:
$subjectareajoin = implode(',', $_SESSION['SubjectArea']);
The query for the Recordset is as follows:
$query_classlist = "SELECT DISTINCT Class FROM $table_name
WHERE SubjectArea IN ('$subjectareajoin') AND CentreNo LIKE '".$_SESSION['CentreNo']."'
ORDER BY Class ASC";
$classlist = mysql_query($query_classlist) or die(mysql_error());
$row_classlist = mysql_fetch_assoc($classlist);
$totalRows_classlist = mysql_num_rows($classlist)
But it keeps telling me that there is an error with the Array to String conversion:
Notice: Array to string conversion in path\addteachertest.php on line 28
This is the initial query to create the subjectarea array:
$query_subjectarea = mysql_query("SELECT DISTINCT SubjectArea FROM $table_name
WHERE Initials = '".$_SESSION['Initials']."'
AND staff LIKE '%".$_SESSION['Surname']."'") or die(mysql_error());
$query_subjectarea_array = array();
while($row_query_subjectarea = mysql_fetch_array($query_subjectarea))
$query_subjectarea_array[] = $row_query_subjectarea;
This is var_dump($query_subjectarea_array):
array(1) { [0]=> array(2) { [0]=> string(15) "Expressive Arts" ["SubjectArea"]=> string(15) "Expressive
Arts" } }
If anybody could tell me what is wrong with my approach that would be grand. Many thanks in advance!
mysql_real_escape_string($value_no_injection)
for ALL STRINGS inside queries.