我有以下代码
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<div class="col-md-3">
<div class="single-post">
<img src="img/cars/'.$row["fahrzeugBild"].'.jpg" alt="">
<h4><span class="author-name">Modell: '.$row["fahrzeugName"].'</span></h4>如何将$output放入If else语句中?因此,如果$row为空,它应该不返回任何内容。
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
echo <div class="col-md-3">
echo <div class="single-post">
If .$row["fahrzeugBild"] empty then
nothing
else
echo <img src="img/cars/'.$row["fahrzeugBild"].'.jpg" alt="">
If .$row["fahrzeugName"] empty then
nothing
else
echo <h4><span class="author-name">Modell: '.$row["fahrzeugName"].'</span></h4>发布于 2020-04-12 05:35:55
你已经做了很好的努力,它显示在你的问题的细节中。
根据你的意思,你可以在几个地方使用if语句。
好了,我想我现在明白了。除了$output之外,您还希望$row的各个元素控制各个元素。
这将需要一系列检查,就像您所做的那样,但不是在字符串本身内部。
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)) {
if ($row == "") {
// do one thing
} else {
$output .= '<div class="col-md-3"><div class="single-post">';
if ($row["fahrzeugBild"] !== "") {
$output .= '<img src="img/cars/'.$row["fahrzeugBild"].'.jpg" alt="">';
}
if ($row["fahrzeugName"] !== "") {
$output .= '<h4><span class="author-name">Modell: '.$row["fahrzeugName"].'</span></h4>';
}
// and so forth for all of your other cases
}https://stackoverflow.com/questions/61163861
复制相似问题