增量$ i不在函数中返回1 ++
function show7days()
{
$sql = mysql_query("SELECT * FROM `movies` WHERE dateuploaded >= DATE_SUB(NOW(), INTERVAL 7 DAY) order by visits desc LIMIT 7");
while ($row=mysql_fetch_array($sql)) {
$name = $row[2];
$descr = $row[3];
$img = $row[4];
$i=1;
echo "<p align=\"center\">$i.$i++<a href=\"/movie/".($row[2])."\"><img src=\"/movie/".($img)."\ height=\"30\" width=\"30\";></a><br><a href=\"/movie/$row[2]\">$name</a></p>";
}
}
答案 0 :(得分:1)
每次因为在循环内初始化而得到相同的值。你错过了报价。
$i=1;// keep this outside.
while($row=mysql_fetch_array($sql)) {
$name = $row[2];
$descr = $row[3];
$img = $row[4];
echo "<p align=\"center\">".$i++."<a href=\"/movie/".($row[2])."\"><img src=\"/movie/".($img)."\ height=\"30\" width=\"30\";></a><br><a href=\"/movie/$row[2]\">$name</a></p>";
^ ^//missed the quotes aswell
}
答案 1 :(得分:0)
$i=1;
$sql = mysql_query("SELECT * FROM `movies` WHERE dateuploaded >= DATE_SUB(NOW(), INTERVAL 7 DAY) order by visits desc LIMIT 7");
while($row=mysql_fetch_array($sql)) {
$name = $row[2];
$descr = $row[3];
$img = $row[4];
echo "<p align=\"center\">$i.$i++<a href=\"/movie/".($row[2])."\"><img src=\"/movie/".($img)."\ height=\"30\" width=\"30\";></a><br><a href=\"/movie/$row[2]\">$name</a></p>";
}
}
It may solve your problem