1 回答
TA贡献1796条经验 获得超4个赞
以下是我的建议:
mysqli_stmt_store_result()
永远不要使用,除非您确切地知道它的用途。使用mysqli_stmt_get_result()
来代替。无论如何 - 你不应该混合这两个功能。不要
mysqli_stmt_num_rows()
在结果上使用。使用mysqli_num_rows($result)
来代替。切换到对象方法而不是全局函数调用。例如:
$result->num_rows
而不是mysqli_num_rows($result)
. 代码会更短,您将无法使用参数类型错误的函数,例如mysqli_stmt_num_rows($result)
.使用
MYSQLI_ASSOC
代替MYSQLI_NUM
。或使用mysqli_fetch_assoc()
.
您的代码应该如下所示:
$stmt = $conn->prepare("SELECT * FROM `assets`");
$stmt->execute();
$result = $stmt->get_result()
if (!$result) {
die("Could not show the required data");
} elseif ($result->num_rows == 0) {
echo "Currently there are no assets to be shown.";
} else {
echo '<table id="table" class="display"><thead> [..]';
while($result2 = $result->fetch_assoc()) {
$class="";
if ($result2["Review_date"] < date('Y-m-d')){
$class=" old";
} elseif($result2["Review_date"] < date('Y-m-d', strtotime('+6 days'))){
$class="notnew";
} else {
$class="new";
}
echo '<tr class="'.$class.'">
<td>'.$result2["Asset_name"].'</td>
[..]
</tr>';
}
echo '</tbody></table>';
}
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报