Numerating Comments

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-12T20:02:36Z Indexed on 2010/04/12 20:13 UTC
Read the original article Hit count: 315

Filed under:
|

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 = 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>"

© Stack Overflow or respective owner

Related posts about php

Related posts about beginner