아래 입력은 "datesubmitted"라는 타임 스탬프 필드로 제출을 시간순으로 역순으로 정렬합니다. 이 필드는 "제출"이라는 MySQL 테이블에 있습니다.두 필드로 정렬
또 다른 MySQL 테이블 "comment"에는 "datecommented"라는 다른 타임 스탬프 필드가 있습니다.
각 제출에는 단 하나의 "datesubmitted"가 있지만 여러 개의 주석이있을 수 있으며 각 주석에는 "날짜가 서로 다릅니다."
"datesubmitted"및 각 "datecommented"의 제출을 어떻게 정렬 할 수 있습니까? 즉,이 목록의 맨 위에 가장 최근에 제출 된 항목 또는 가장 최근에 작성한 항목이있는 항목 중 어느 것이 든 이 가장 최근에 인 항목을 표시하도록합니다. 사전에
감사합니다,
존
$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>";
'LEFT'과 'OUTER'사이에 줄 바꿈이 없습니다. ;-) –