下面的代码按时间顺序打印出给定"submissionid"的所有注释.我怎么能算出这些评论呢?(换句话说,如何打印最旧评论旁边的"1",第二个最老评论旁边的"2"等?)
$submission = mysql_real_escape_string($_GET['submission']);
$submissionid = mysql_real_escape_string($_GET['submissionid']);
$sqlStr = "SELECT comment.comment, comment.datecommented, login.username
FROM comment
LEFT JOIN login ON comment.loginid=login.loginid
WHERE submissionid=$submissionid
ORDER BY comment.datecommented ASC
LIMIT 100";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"commentecho\">";
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td class="commentname1">'.stripslashes($row["comment"]).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="commentname2"><a href="http://www...com/sandbox/members/index.php?profile='.$row["username"].'">'.$row["username"].'</a>'.date('l, F j, Y &\nb\sp &\nb\sp g:i a &\nb\sp &\nb\sp \N\E\W &\nb\sp \Y\O\R\K &\nb\sp \T\I\M\E', strtotime($row["datecommented"])).'</td>';
echo '</tr>';
}
echo "</table>"
Run Code Online (Sandbox Code Playgroud)
显示代码的相关部分,休息注释掉,以便您立即看到我添加的内容:
//echo "<table class=\"commentecho\">";
$count = 1; //<-start counter
//while ($row = mysql_fetch_array($result)) {
//echo '<tr>';
echo '<td>'.$counter++.'</td>'; //<-use numbering and increment afterwards
//echo '<td class="commentname1">'.stripslashes($row["comment"]).'</td>';
//echo '</tr>';
//..
}
//echo "</table>";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |