Page 1 of 1

Order Private Messages by top/latest bottom/earliest?

Posted: Tue Aug 26, 2008 12:50 pm
by JAB Creations
Please forgive me (and feel free to move the thread to the Database section if applicable) though I'm trying to figure out how to order messages in the private message system I've setup by date. By default I want to display the newest messages at the top and going down the list to earlier messages. I figure this may be a PHP issue to scan the $row['date_0'] (which is the sent date where as date_1 is the read date) though I'm not familiar enough to presume that I could not somehow do this with MySQL.

Since it's a message system the $row is defined inside of the while loop. I'm not looking for a direct answer though it would be nice. I'm actually having difficulty with the MySQL documentation. I eventually got used to W3C's and after a redesign can now figure out Apache. So I'm much more interested in learning how to independently research the topic so I can at least make more of an educated guess versus an empty handed sort of question. Here is the minimal though most applicable code I think is relevant to achieving this goal...

Code: Select all

if (!isset($_GET['folder'])) {$result1 = mysql_query("SELECT id, id_from, date_0, date_1, message, subject FROM `public_private_messages` WHERE id_for = '".$_SESSION['member']."' OR id_for_folder = 'New'");} // AND id_for_folder = 'Read'
 
if (!$result1) {$_SESSION['error'] = mysql_error(); header("location:messages.php?error");}
while($row = mysql_fetch_array($result1))
{
 echo '<tr id="message_'.$row['id'].'"><td><input class="checkbox" type="checkbox" value="" /></td>'."\n";
 echo '<td>'.$row['id_from'].'</td>'."\n";
 echo '<td>'.$row['date_0'].'</td>'."\n";
 echo '<td><a href="messages.php?message='.$row['id'].'">'.$row['subject'].'</a></td></tr>'."\n";
}

Re: Order Private Messages by top/latest bottom/earliest?

Posted: Tue Aug 26, 2008 1:04 pm
by jayshields
Add an ORDER BY `date_0` DESC clause to the end of your query.

I find Firefox's search engine plug-ins useful for searching manuals, here is a link to some MySQL ones http://mycroft.mozdev.org/search-engine ... name=mysql

Re: Order Private Messages by top/latest bottom/earliest?

Posted: Tue Aug 26, 2008 1:26 pm
by JAB Creations
Yeah!

YEAH!

YEAH!

Awesome thanks!

I don't even know why I'm asking this! After you mentioned that I switch to the phpMyAdmin tab and there it is...the column header text is anchored...and for the win phpMyAdmin gives you the execution code!

I've added the MYSQL 5.1 manual to Firefox's quick search providers. Thanks a ton!