Code: Select all
<?
IF($orderby == "teacher" AND $arrangement == "ASC"){
$teacher_link = "homework.php?orderby=teacher&arrangement=DESC";
$subject_link = "homework.php?orderby=subject&arrangement=ASC";
$date_link = "homework.php?orderby=date&arrangement=ASC";
}
IF($orderby == "teacher" AND $arrangement == "DESC"){
$teacher_link = "homework.php?orderby=teacher&arrangement=ASC";
$subject_link = "homework.php?orderby=subject&arrangement=ASC";
$date_link = "homework.php?orderby=date&arrangement=ASC";
}
IF($_GETїorderby] != "teacher" AND $_GETїorderby] != "" AND $_GETїarrangement] != ""){
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$order = "ORDER BY $_GETїorderby] $_GETїarrangement]";
}elseif($_GETїorderby] == "teacher" AND $_GETїorderby] != "" AND $_GETїarrangement] != ""){
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$order = "ORDER BY SUBSTRING_INDEX(teacher, ' ', -1),SUBSTRING_INDEX(teacher, ' ',1) $_GETїarrangement]";
}Code: Select all
<?
$color1 = "#FF6103";
$color2 = "#FFA54F";
$row_count = 0;
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$query=mysql_query("SELECT * FROM assignments $order");
while ($row = mysql_fetch_array($query)) {
$teacher=$rowї"teacher"];
$subject=$rowї"subject"];
$date=$rowї"date"];
$assignment=$rowї"assignment"];
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "
<tr onMouseOver="this.bgColor = '#E8E8E8'" onMouseOut = "this.bgColor = '$row_color'" bgcolor='$row_color'>
<td align='center' width='25%'>
$teacher</td>
<td align='center' width='25%'>
$subject</td>
<td align='center' width='25%'>
$date</td>
<td align='center' width='25%'>
$assignment</td>
</tr>
";
$row_count++;
}
?>This code will make the table order by REVERSE alphabetical order, but it won't go back to alphabetical order if I click the link again. I know my code is wrong, but what should I write otherwise?
For the second part of my question:
I store the date the teacher says the assignment is due in the DB as the fields "month","day","year". If I want to sort by date, how would I? The dates are stored as the words "January, February,etc...", "1,2,etc...", and "05,06,etc...".