Yorumlar Numarataj

1 Cevap

Aşağıdaki kod kronolojik olarak verilen bir "submissionid" için tüm yorumları yazdırır. Nasıl ben bu yorumların numerate olabilir? (Başka bir deyişle, nasıl bir "1". Yazdırmak yok yanındaki eski yorumuna, "2". Sonraki vb eski ikinci açıklama, nasıl?)

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

1 Cevap

Kodun ilgili kısmını gösteren, böylece hemen ben ekledi görmek üzerinden yorumladı dinlenme:

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