这个While循环让我疯狂

sar*_*hak 1 php sql database loops while-loop

我想简单地使用带有php的while循环显示一些内容,但它无法正常工作.

这是代码 -

<?php 

mysqli_select_db($connect,"users");

$select_title = "select title, message from messages where user = '$u' LIMIT 4 ";

$querying = mysqli_query($connect,$select_title) or die ('Whops! Something went wrong.');

$line = mysqli_fetch_assoc($querying);

    //$title = mysqli_real_escape_string($connect,trim($line['title']));

while(($rows = mysqli_fetch_assoc($querying)))
{

    echo $rows['title'];
}
Run Code Online (Sandbox Code Playgroud)

?>

现在我有两个标题,但只显示了一个.为什么这样?

nan*_*nan 6

你在这里拿了一行:

$line = mysqli_fetch_assoc($querying);
Run Code Online (Sandbox Code Playgroud)

因此,光标将移动到下一行

while(($rows = mysqli_fetch_assoc($querying)))
{

    echo $rows['title'];
}
Run Code Online (Sandbox Code Playgroud)

将仅显示第二行.

最好的解决方案就是评论该行:

 //$line = mysqli_fetch_assoc($querying);
Run Code Online (Sandbox Code Playgroud)