2016-07-29 25 views
-1

我想用数据库中的数据填充表。我已经广泛地用Google搜索,但似乎没有任何工作与PHP填充表不断给我常见的错误

我总是不断收到空表与以下错误:**警告:mysqli_fetch_assoc()期望的是1个参数,2 **

事情给出是,如果我只给它1个参数,然后页面停留在旋转装载机上。我的HTML代码

部分:

<?php 
ini_set('display_errors', 'On'); 
error_reporting(E_ALL | E_STRICT); 

session_start(); 
include 'config.php'; 

$query_string = "SELECT * FROM tbl_User"; 

$query = mysqli_query($con, $query_string); 


?><!DOCTYPE html> 
<html lang="en"> 
<head> 

.... 

</head> 
<body> 
    <table id="myTable" class="table table-striped"> 
       <thead> 
       <tr> 
        <th>Name</th> 
        <th>Email</th> 
        <th>Profile Picture</th> 
        <th>Role</th> 
       </tr> 
       </thead> 
       <tbody> 
       <?php 
        while($row = mysqli_fetch_assoc($con, $query)){ 
        echo "<tr>"; 
        echo "<td>".$row['name']."</td>"; 
        echo "<td>".$row['email']."</td>"; 
        echo "</tr>"; 
        }  
       ?> 
       </tbody> 
      </table> 

代码的config.php:

<?php 
$con = mysqli_connect("localhost", "root", "root", "chall") or die("Error " . mysqli_error($con)); 
?> 

请任何人有一个想法如何解决这个问题。

+1

不通过连接到'mysqli_fetch_assoc($ CON,$查询)){' – Saty

+0

正如错误状态;你没有阅读手册吗? –

+0

@Saty,是的,但如果我离开它。该页面卡在我的旋转装载机上...... – GY22

回答

2

使用

while($row = mysqli_fetch_array($query)){ 
    echo "<tr>"; 
    echo "<td>".$row['name']."</td>"; 
    echo "<td>".$row['email']."</td>"; 
    echo "</tr>"; 
} 

不要通$内fetch_array CON/FETCH_ASSOC