if ($num_rows > 0)
{
while($row=mysql_fetch_assoc($res))
{
$fromuser=$row['username'];
$comment=$row['comment'];
$commentdate=$row['date'];
$date=strtotime($commentdate);
$final_date=date("g:i a", $date);
$final_date2=date("F j Y", $date);
?>
<table align="center" width="100%"style='border-top: 1px dotted;'bgcolor="#eeeeee" >
<tr><td><?echo "<a href=\"userprofile.php?user=$fromuser\"><b>$fromuser</b></a> commented:\n";?></td></tr>
<tr><td><?echo "at $final_date on $final_date2\n";?></td></tr>
<tr bgcolor="#ffffff"><td><?echo "$comment\n";?></td></tr>
</table><br>
<?
}
}
else
{
echo"There are currently no comments on this user";
}
?>
我正在寻找一种方法来为每条评论添加一个数字。所以在DESC顺序中有1,2,3,4等。 我想不出我怎么能这样做?
答案 0 :(得分:2)
我在您的代码中添加了几行,可以实现您想要的效果。
if ($num_rows > 0)
{
$number = $num_rows;
while($row=mysql_fetch_assoc($res))
{
$fromuser=$row['username'];
$comment=$row['comment'];
$commentdate=$row['date'];
$date=strtotime($commentdate);
$final_date=date("g:i a", $date);
$final_date2=date("F j Y", $date);
?>
<table align="center" width="100%"style='border-top: 1px dotted;'bgcolor="#eeeeee" >
<tr><td><?echo $number;?><td><?echo "<a href=\"userprofile.php?user=$fromuser\"><b>$fromuser</b></a> commented:\n";?></td></tr>
<tr><td><?echo "at $final_date on $final_date2\n";?></td></tr>
<tr bgcolor="#ffffff"><td><?echo "$comment\n";?></td></tr>
</table><br>
<?
$number -= 1;
}
}
else
{
echo"There are currently no comments on this user";
}
?>
答案 1 :(得分:1)
$counter = $num_rows;
while($row=mysql_fetch_assoc($res))
{
{
// ... your code
$counter -= 1;
echo $counter;
}
答案 2 :(得分:0)
在您的循环中添加$no++
增量并将其显示在我的表<td><?= $no ?><?td>