I've already posted this but I want to explain it better. I have a website in which students insert their 4 courses and 4 comments for each course, these are the SQL table columns: Course1, Course2, Course 3, Course 4, Comment1, Comment2, Comment 3, Comment 4.
I have a search in which any student inputs, for instance, geography (which may be saved in any of the four course columns), and I want my SQL query to return all the comments for geography. For example, if a student saved Geography in position Course2, I want my SQL query to select comment2 where course2 = geography. He may have saved it in course1, so it has to be flexible, but only select the course chosen by the student. This is my current SQL query:
$SQL = "SELECT (Comment1 FROM Students WHERE Course1 = 'geography'), (Comment2 FROM Students WHERE Course2 = 'geography'), (Comment3 FROM Students WHERE Course3 = 'geography'), (Comment4 FROM Students WHERE Course4 = 'geography')";
Currently, this SQL query isn't working. I know the structure may seem odd, but logically, as you may understand, this makes sense, though it's probably not the right way to code it. I then print all the geography comments like this:
$null = '';
if(mysql_num_rows($result)) {
echo "<ol>";
while ($row=mysql_fetch_array($result)) {
if($row["Class"]!=$null) {
if($null!='') {
echo "</ol><ol type='1'>";
}
}
echo "<li><p>" . " " . $row["Comment1"]. " " . $row["Comment2"]." " . $row["Comment3"] . " " . $row["Comment4"] . "</li></p>";
$i = $i +1;
}
echo "</ol>";