我想在PHP中显示数据库结果,但它一直给出相同的错误

时间:2017-11-11 08:39:57

标签: php mysql html-table

<?php 
require_once('../mysql_connect.php');

$query = "SELECT customerName
                FROM customerName
                WHERE membership = 0";

$result=mysqli_query($dbc,$query);


echo '<table width="75%" border="1" align="center" cellpadding="0" 
cellspacing="0" bordercolor="#000000">
<tr>
<td width="10%"><div align="center"><b>CUSTOMER NAME
</div></b></td>
<td width="10%"><div align="center"><b>APPROVE
</div></b></td>
<td width="10%"><div align="center"><b>REJECT
</div></b></td>
</tr>';

while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){

echo "<tr>
<td width=\"10%\"><div align=\"center\">{$row['customerName']}
</div></td>

<td width=\"10%\"><div align=\"center\"> /*this is supposed to show a button*/
</div></td>
<td width=\"10%\"><div align=\"center\"> /*this is supposed to show a button*/
</div></td>

</tr>";


}
echo '</table>';
?>

我想用PHP显示我的数据库的内容 所以我使用了另一个程序使用的代码!

while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))

(这个语句应该是指db / row有内容吗?)

 $result=mysqli_query($dbc,$displayName);

每当我将它用于我的程序时,它会一遍又一遍地给出同样的错误,错误就是:

  

mysqli_fetch_array()期望参数1为mysqli_result

我给它mysqli_result  但它说我给了一个布尔值!  我试图将mysqli_result包含在''中,因为前面的错误就像是期待'mysqli_result',但它变成了一个字符串,所以我尝试将mysqli_fetch_array更改为mysqli_fetch_row,这显示了同样的错误!!  也是因为我想在桌子上显示按钮?

1 个答案:

答案 0 :(得分:1)

它可能对您有所帮助。

  

db.php中

<?php
    $conn = mysqli_connect('localhost','root','','crud_db');

    if(!$conn){
        die('error connecting to database');
    }
?>
  

的index.php

<?php


    require_once('db.php');

        $query = "SELECT *
                    FROM employees";

    $result=mysqli_query($conn,$query);


    echo '<table width="75%" border="1" align="center" cellpadding="0" 
    cellspacing="0" bordercolor="#000000">
    <tr>
    <td width="10%"><div align="center"><b>EMPLOYEE NAME
    </div></b></td>
    <td width="10%"><div align="center"><b>APPROVE
    </div></b></td>
    <td width="10%"><div align="center"><b>REJECT
    </div></b></td>
    </tr>';

    while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){

    echo "<tr>
    <td width=\"10%\"><div align=\"center\">{$row['ename']}
    </div></td>

    <td width=\"10%\"><div align=\"center\"> <button type=\"button\">Approve</button>
    </div></td>
    <td width=\"10%\"><div align=\"center\"> <button type=\"button\">Reject</button>
    </div></td>

    </tr>";


    }
    echo '</table>';

?>

enter image description here