我正在设置一个新的主中心(dashboard.php),以使其自动显示库存中的项目及其相应的值。而是显示此错误:
“致命错误:无法在第31行的C:\ xampp \ htdocs \ commissary \ dashboard.php中将mysqli_result类型的对象用作数组”
这是我代码的php部分:
<?php
$query = 'SELECT * FROM inventory';
$result = mysqli_query($conn, $query);
if(!$result){
echo mysqli_error($conn);
exit();
}
while($row = mysqli_fetch_assoc($result)){
echo "<h1>'{$result['iname']}'</h1>";//this is line 31
echo "<h1>'{$result['amount']}'</h1>";
}
?>
在很大程度上,这是我在sql中使用的表:
CREATE TABLE `inventory` (
`inv_id` int(11) NOT NULL,
`iname` varchar(255) NOT NULL,
`amount` int(11) NOT NULL
);
ALTER TABLE `inventory`
ADD PRIMARY KEY (`inv_id`);
ALTER TABLE `inventory`
MODIFY `inv_id` int(11) NOT NULL AUTO_INCREMENT;