开发者

Numerating Comments

The code below prints out all comments for a given "submissionid" in chronological order. How could I numerate these comments? (In other words, how do I print out a "1." next to the oldest comment, a "2." next to the second-oldest comment, etc.?)

$submission =开发者_JS百科 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>"


Showing relevant part of code, rest commented out so you immediately see what i added:

//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>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜