Hello,
The input below sorts submissions by a timestamp field called "datesubmitted" in reverse chronological order. This field is in a MySQL table called "submission."
Another MySQL table "comment" has another timestamp field called "datecommented."
Each submission has only one "datesubmitted" but it could have several comments, each with a different "datecommented."
How could I sort the submissions by "datesubmitted" and each one's last "datecommented"? In other words, I want the top of this list to show either the most recently submitted entry or the entry with the most recent comment, whichever occurred most recently.
Thanks in advance,
John
$sqlStr = "SELECT
s.loginid
,s.title
,s.url
,s.displayurl
,s.datesubmitted
,l.username
,s.submissionid
,COUNT(c.commentid) countComments
FROM
submission s
INNER
JOIN
login l
ON
s.loginid = l.loginid
LEFT OUTER
JOIN
comment c
ON
s.submissionid = c.submissionid
GROUP
BY
s.submissionid
ORDER
BY
s.datesubmitted DESC
LIMIT
10";
$tzFrom = new DateTimeZone('America/New_York');
$tzTo = new DateTimeZone('America/Phoenix');
// echo $dt->format(DATE_RFC822);
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"samplesrec\">";
while ($row = mysql_fetch_array($result)) {
$dt = new DateTime($row["datesubmitted"], $tzFrom);
$dt->setTimezone($tzTo);
echo '<tr>';
echo '<td class="sitename1"><a href="http://www.'.$row["url"].'" TARGET="_blank">'.$row["title"].'</a> <div class="dispurl">'.$row["displayurl"].'</div></td>';
echo '</tr>';
echo '<tr>';
echo '<td class="sitename2name">Submitted by <a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.$row["username"].'</a> on '.$dt->format('F j, Y &\nb\sp &\nb\sp g:i a').'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="sitename2"><a href="http://www...com/.../comments/index.php?submission='.$row["title"].'&submissionid='.$row["submissionid"].'&url='.$row["url"].'&countcomments='.$row["countComments"].'&submittor='.$row["username"].'&submissiondate='.$row["datesubmitted"].'&dispurl='.$row["displayurl"].'">'.$row["countComments"].' comments</a></td>';
echo '</tr>';
}
echo "</table>";