我有这段代码,我一直在处理它,当我运行它时,我得到了第一个结果 10 次(它曾经无限重复,直到我添加了 if 语句)。它应该返回前 10 个结果。我查看了其他几个类似的问题,但没有一个解决方案在这里有效。谁能看到我错过了什么?
<?php
$link = mysql_connect('XXXXXXXXX.com', 'XXXXXX', 'XXXXX');
$db = mysql_select_db('a1007515_troop1', $link);
$i = 1;
while($row = mysql_fetch_array(mysql_query('SELECT * FROM `posts` ORDER BY `pid` DESC LIMIT 10;')))
{
$authinfo = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = '.$row['aid'].' LIMIT 1'));
echo '
<div class="content">
<a href="post.007?pid='.$row['pid'].'"><h1 class="title">'.$row['title'].'</h1></a>
<span class="authinfo">This post was made by '.$authinfo['name'].'<i>('.$authinfo['username'].')</i> on '.$row['date'].'.</span>
<p class="txt">'.$row['content'].'</p>
</div>';
if ($i == 10) { break; }
++ $i;
}
mysql_close($link);
?>