【问题标题】:Can't loop more than 1 row Mysql不能循环超过 1 行 Mysql
【发布时间】:2016-10-17 10:03:19
【问题描述】:

我正在尝试从数据库中获取所有行,但是当我的数据库只有 1 行时,它会显示在网站上,如果我添加更多的 1 行,网站上不会显示任何内容。

我的代码:

require_once('data/class.dbsetting.php');

Mysql sql = new Mysql();

sql->connect();

$query = 'select * from accounts';
$result = $sql->query($query);

While($row = $sql->fetch_assoc($result))
{
  echo $row['Username'];
}

【问题讨论】:

  • 请添加var_dump($result); 并告诉我们结果
  • 奇怪的是你使用new mysql() 并使用它。我不知道您是否将其隐藏在问题的代码中,或者您是否没有使用任何连接数据。
  • 对不起,我的课是mySql,会是mySql sql = new mySql();
  • 这里 var_dump($result), object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(11) ["lengths "]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }

标签: php database mysqli while-loop


【解决方案1】:

尝试:

mysql_fetch_all($result,MYSQL_ASSOC);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多