How to reverse the order of an already ordered mysql_query
<p>I have a fairly difficult question today and I don't know if it is possible to do, but If it is it would really help me out.  Here is my code:</p>

<pre><code>$chatquery = mysql_query("SELECT * FROM conversation 
                          WHERE yourusername='$username' AND 
                          theirusername='$otherchatuser' 
                          ORDER BY ID DESC");

while ($runrows = mysql_fetch_assoc($chatquery))
{
    $chatname = $runrows['realuserusername'];
    $chatmessage = nl2br($runrows['message']);
    $chatmessage = preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&amp;\/\/=]+)/i',
                                '&lt;a href="\\1" style="color:#36648B;" target="_blank"&gt;\\1&lt;/a&gt;', 
                                $chatmessage);

    $chatmessage = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&amp;\/\/=]+)/i',
                                '\\1&lt;a href="http://\\2" style="color:#36648B;" target="_blank"&gt;\\2&lt;/a&gt;', 
                                $chatmessage);

    $chatlocation = $runrows['imagelocation'];
    $chatimage = "&lt;img src='$chatlocation' style='width:25px; height:20px;' /&gt;";

    echo '&lt;table style="margin-bottom:5px;"&gt;
            &lt;tr&gt;
                &lt;td valign="top" style="padding-right:5px;"&gt;'.$chatimage.'&lt;/td&gt;
                &lt;td&gt;&lt;div style="max-width:220px; word-wrap:break-word;"&gt;'.$chatmessage.'&lt;div&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;';
}
</code></pre>

<p>This is a chat plugin and right now all of the messages display in <code>DESC</code> order, which is what I want.  However what i a m trying to do is if my query gets the same user, <code>$chatname</code>, more than once in a row, I want it to display those messages in <code>ASC</code> order and not to display the <code>$chatname</code> again.  Then, once it gets a different <code>$chatname</code> it keeps going in <code>DESC</code> order.  So it is like reversing a query.  I do not know if it is possbile but any help would be appreciated.</p>

<p>My last question, based on the response of DaveRandom and using the code he put below.  Where the user name repeats, I would like to have the code</p>

<pre><code>$usermessage = '&lt;table&gt;&lt;tr&gt;&lt;td valign="top" style="padding-right:5px;"&gt;&lt;/td&gt;&lt;td&gt;&lt;div style="max-width:220px; word-wrap:break-word;"&gt;'.$chatmessage.'&lt;div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
</code></pre>

<p>And where it does not I would like to have</p>

<pre><code>    $usermessage = '&lt;table style="margin-bottom:5px;"&gt;&lt;tr&gt;&lt;td valign="top" style="padding-   right:5px;"&gt;'.$chatimage.'&lt;/td&gt;&lt;td&gt;&lt;div style="max-width:220px; word-wrap:break-   word;"&gt;'.$chatmessage.'&lt;div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
</code></pre>

<p>How would I go about doing this?</p>
