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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.