当我删除&& $f<4它时,下面的代码工作正常,但有了它,它不起作用.
PHP:
$titles=array();
$f=0;
while ($row=mysql_fetch_assoc($query) && $f<4){ //this line doesn't work
$titles[]=$row['questiontitle'];
echo "<div class='questionPreview'>$titles[$f]</div>";
$f++;
}
Run Code Online (Sandbox Code Playgroud)
如果我正确地解释你,我认为你有一个优先问题.试试这个:
while (($row=mysql_fetch_assoc($query)) && ($f<4)){
Run Code Online (Sandbox Code Playgroud)