我想表明在PHP数据库的结果,但它一直给了同样的错误
问题描述:
<?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 所以我用从其他程序中使用的代码!我想表明在PHP数据库的结果,但它一直给了同样的错误
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
(这种说法的解释是:当DB /行有内容?)
$result=mysqli_query($dbc,$displayName);
每当我用我的程序一遍又一遍地给了我同样的错误,错误的是:
mysqli_fetch_array()预计参数1被mysqli_result
我给它mysqli_result
但它说我给了布尔值! 我尝试将mysqli_result放在''中,仅仅是因为前面的错误就像是期待'mysqli_result',但它变成了一个字符串,所以我试图将mysqli_fetch_array
更改为mysqli_fetch_row
,它显示了相同的错误! 也是因为我想要在表格中显示按钮?
答
推荐给您的消息对其有帮助。
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>';
?>
非常感谢您!我已经工作了,我意识到我的'FROM'部分查询是错误的,因为它正在寻找一个列而不是一个表。另一方面谢谢你:) –