php - 警告:php 中的参数无效
问题描述
此文件为 foreach 提供了错误无效参数。有没有人解决这个问题。我尝试了很多时间,但我找不到它,我不知道如何解决这个问题。这是我的代码:
<?php
include('connect.php');
$query = "SELECT * FROM product";
$result = mysqli_query($connect,$query);
$output ='<table class="table table-stripped table-bordered">
<tr><th>Product Name</th>
<th>Product Type</th>
<th>Product Rate</th>
<th>Brand</th>
<th>Edit</th>
<th>Insert</th>
</tr>';
if(mysqli_num_rows($result)>0)
{
foreach (mysqli_num_rows($result) as $row) {
$output .= '<tr>
<td width="40%">'.$row["product_name"].'</td>
<td width="40%">'.$row["product_type"].'</td>
<td width="40%">'.$row["product_rate"].'</td>
<td width="40%">'.$row["brand"].'</td>
<td width="10%">
<button type="button" name="edit" class="btn btn-primary btn-xs edit" id="'.$row["id"].'">Edit</button>
</td>
<td width="10%">
<button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row["id"].'">Delete</button>
</td>
</tr>';
}
}
else
{
$output .='<tr>
<td colspan ="4" align="center"> No data Found</td>
</tr>' ;
}
$output .= '</table>';
echo $output;
?>
解决方案
mysqli_num_rows
函数返回一个数字,而不是一个数组。您可能想使用mysqli_fetch_all:
foreach (mysqli_fetch_all($result) as $row) {
}
推荐阅读
- python - Python中名为Path的函数
- sequelize.js - Sequelize:创建后未立即找到列
- swift - 使用 uitextfield 委托通过其计数获取 coredata 二进制数据
- python - 试图从 tkInter 比例中保存值
- swift - 在 SwiftUI 中的 ActionSheet 上设置辅助功能标识符
- flutter - 在 Flutter 中使用 StreamProvider 4.0.1 从 Firebase 监控身份验证状态
- reactjs - 如何格式化 Redux Form 上使用的输入?
- python - 启动笔记本的 Jupyter 问题(权限被拒绝)
- kernel - BIOS 中断 0x10 导致从 QEMU 中的 ROM 循环引导
- python-3.x - 谷歌数据流传递数据存储键作为输入参数