PHP循环查询,第一行

时间:2011-01-20 01:35:16

标签: php mysql while-loop

我正在尝试输出第一行的特殊内容,但它似乎在每一行输出,这是我使用的代码:

$query = mysql_query("SELECT * FROM chat WHERE id > '".$_GET["latest"]."' ORDER BY id DESC LIMIT 0, 20");
$number = mysql_num_rows($query);
$i = 1;
while ($row = mysql_fetch_assoc($query)) {

echo "<div class='babble' style='width:130px;overflow:hidden;margin:auto;'><a href=\"javascript:ajaxpage('user_profile.php?game=1&ajax=1&user=".$row['author']."', 'content');\" style=\"cursor:pointer;\"><font color=#ff4355><b>".$row['author']."</b></font></a><font color=#ff4355>:</font></b> ".$row['babble']."</div>";
   if($i = 1)
   {
       echo "<script type='text/javascript'>newestid=".$row['id']."</script>";
$i = 2;
    }
}

1 个答案:

答案 0 :(得分:7)

您需要在==声明中使用comparison operator =,而不是assignment operator if

if ($i == 1)