1

我对php很陌生,我正在自学。我查看了一些不同的资源,我现在拥有的 php 脚本在执行时没有返回任何严重错误,但它没有返回表中的数据。

 <?php

$connect = mysqli_connect("localhost","*","*","*");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$comments = "SELECT * FROM commentstable";

$rs = mysqli_query($connect,$comments);

$fetch = mysqli_fetch_array($rs);

while($fetch = mysqli_fetch_array($rs)) {
    echo $fetch['comments'];

    }
echo $fetch;

mysqli_close($connect);

echo "hello";

?>
4

2 回答 2

1

你有双重输入:

$fetch = mysqli_fetch_array($rs); //<--- remove this as you are calling it again in the while loop

while($fetch = mysqli_fetch_array($rs)) {    
    echo $fetch['comments'];

}
于 2013-11-07T01:07:57.460 回答
0

检查这个

$connect = mysqli_connect("localhost","turlough","samus1","comments");
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
    $comments = "SELECT * FROM commentstable";

    $rs = mysqli_query($connect,$comments);
    if($rs)
    {
        while($fetch = mysqli_fetch_array($rs)) {
            echo $fetch['comments'];
        }
    }
    else
    {
        // no results from query
    }

    mysqli_close($connect);

}
于 2013-11-06T22:05:40.503 回答