gpt4 book ai didi

php - 如果为空变量

转载 作者:行者123 更新时间:2023-12-01 00:22:40 25 4
gpt4 key购买 nike

我正在使用下面的代码:

<?php

$sql = "SELECT * FROM nieuws ORDER BY id DESC LIMIT 0, 3";

$results = $db->query($sql);

if (empty($results)) {
echo 'Momenteel geen nieuws.';
}

foreach ($results as $row)
{
echo '<h3>';
echo $row['titel'].'<br>';
echo '</h3>';
echo $row['bericht'].'<br>';
echo '<br><br><div style="float: left;"><small>Schrijver: '.$row['schrijver'].'</small></div>';
echo '<div style="float: right; margin-bottom:-20px;"><a href="#">Lees meer...</a></div><br><br><hr>';

}

?>

此代码将从数据库中获取信息。但如果表中没有任何内容,则需要说“Momenteel geen nieuws.”。它没有这么说,我不明白为什么它不......如果有人可以帮助我,那就太好了!

最佳答案

<?php

$sql = "SELECT * FROM nieuws ORDER BY id DESC LIMIT 0, 3";

$results = $db->query($sql);

if (count($results) < 1) {
echo 'Momenteel geen nieuws.';
}else
{
foreach ($results as $row)
{
echo '<h3>';
echo $row['titel'].'<br>';
echo '</h3>';
echo $row['bericht'].'<br>';
echo '<br><br><div style="float: left;"><small>Schrijver: '.$row['schrijver'].'</small></div>';
echo '<div style="float: right; margin-bottom:-20px;"><a href="#">Lees meer...</a></div><br><br><hr>';

}
}

?>

关于php - 如果为空变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21738141/

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