I have a small search page which allows the user to search through a database of notes. The search results are listed by category eg
Subject
Topic
Note
I can search the final results (notes) fine, but I can't sort the topic or subject.
I suspect it is because there are multiple dates for each Topic. I have explored things like 'ORDER BY max(notes.$sort)' but I get an sql error.
Due to my newbie nature I do not know the capabilities of the SQL functions.
Any help would be appreciated, or a more efficient method.
Below is the code I am using
$subjectresult = mysql_query($subjectquery) or die(mysql_error());
while (list($subjectID, $subject) = mysql_fetch_row($subjectresult))
{
SUBJECT NAME HERE
$topicquery = "SELECT DISTINCT notes.topic" . $query . " AND notes.subjectID=$subjectID";
if ($sort)
{
if ($order)
$topicquery .= " ORDER BY notes.$sort $order";
}
$topicresult = mysql_query($topicquery) or die("Error: " . mysql_error());
while (list($topic) = mysql_fetch_row($topicresult))
{
TOPIC NAME HERE
$notequery = "SELECT notes.*" . $query . " AND notes.topic = '$topic'";
if ($sort)
{
if ($order)
$notequery .= " ORDER BY notes.$sort $order";
}
$noteresult = mysql_query($notequery);
$on = true;
while ($note = mysql_fetch_array($noteresult))
{
NOTE STUFF HERE
}
}
}