2010-04-12 4 views
0

아래의 코드는 주어진 "submissionid"에 대한 모든 주석을 시간순으로 인쇄합니다. 이 의견들을 어떻게 나눌 수 있습니까? (즉, 어떻게 등, 옆에 두 번째로 오래된 주석에, 옆에있는 가장 오래된 주석에 "2"는 "1"인쇄합니까?)Numerating Comments

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

답변

7

코드의 관련 부분을보기 나머지는 댓글을 달았으므로 내가 추가 한 내용을 즉시 볼 수 있습니다.

//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>"; 
관련 문제