I have a chunk of code that sorts a database by column. It sorts perfectly for four of the columns but when I cannot get it sort properly by timestamp(MySQL).
The idea is to group by -- say author-- print links to everything by that author, then move on to the next author. The following works except with timestamp. With timestamp it sorts and groups correctly but repeats the same date/group five or six times before moving to the next date/group.
My relevant code looks like this:
$query = "SELECT DISTINCT $order FROM links order by $order DESC";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
$main_sort = $row->$order;
$sub_query = "SELECT * FROM links where ($order='$main_sort')";
$sub_result = mysql_query($sub_query);
if (mysql_num_rows($sub_result)>0)
{
while($sub_row = mysql_fetch_object($sub_result))
{
switch($order)
{
case "timestamp":
echo ( blah blah blah)
}