Jump to content

Sort by date


downah

Recommended Posts

Hey guys,

 

I have got some events, and got it sorted by date, although at the moment the oldest date is showing first, and I would like to turn that around(new first old last), any simple suggestions?

 

Also another little question how would I turn a date row (for example 2009/5/31) into Tuesday - May 2009 or something similar, anyone can point me into the right direction?

Link to comment
https://forums.phpfreaks.com/topic/259863-sort-by-date/
Share on other sites

How is the data structured? Array of OOP objects in PHP? Rows in MySQL?

 

Assuming the former since this is a PHP forum, you can use usort on the array and define your own function to sort by date. Read the manual for more information about writing a user-defined sort function.

Link to comment
https://forums.phpfreaks.com/topic/259863-sort-by-date/#findComment-1331821
Share on other sites


$result = mysql_query("SELECT * FROM Events ORDER BY eventdate");

echo "<table border='0'>
<tr>
<th>Date/Time</th>
<th>Event</th>
<th>Participants</th>
<th>Hoster</th>
</tr>";

while($row = mysql_fetch_array($result))
{

  echo "<tr>";
  echo "<td>" . $row['eventdate'] . " " . $row['starttime'] . "</td>";

echo '<td><a href="showevent.php?eventsID=';
echo $row['eventsID'];
echo '">';
echo $row['eventdescriptionheader'];
echo "</a></td>";
  echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] .  "</td>";
  echo "<td>" . $row['hoster'] . "</td>";
  echo "</tr>";
}
echo '</table>';
}
?>

 

eventdate is a date field in MYSQL

Link to comment
https://forums.phpfreaks.com/topic/259863-sort-by-date/#findComment-1331824
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.