gpt4 book ai didi

php - 检查 mysqli_query 是否为空

转载 作者:行者123 更新时间:2023-11-29 06:44:29 24 4
gpt4 key购买 nike

我正在寻找一种方法来检查我的 mysqli_query 结果是否为空。

我的代码:

$result = mysqli_query($con, "SELECT ......");

然后是表头:

<table class="table table-striped" width="100%">
<thead>
<table class="table table-striped" width="100%">
<thead>
<th>Jahr</th>

然后我用 while 循环生成行:

while($ausgabe = mysqli_fetch_object($result)){ ?>
<tr>
<td><?php echo $ausgabe->jahr; ?></td>

现在我想做一个 if 查询来检查是否必须在表格开始之前显示表格,如下所示:

if($result){    
<table class="table table-striped" width="100%">
<thead>
<th>Jahr</th>

但这不起作用,它只适用于询问 mysqli_fetch_object 是否为空,但此代码位于我的表头下方,因此我无法使用它。

你有什么想法吗?

最佳答案

您可以使用$num_rows

$results = $mysqli->query("SELECT * FROM table");
if($results->num_rows === 0)
{
echo 'No results';
}
else
{
//HERE YOU PROCESS
while(){....}
}

关于php - 检查 mysqli_query 是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50105065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com