gpt4 book ai didi

php - 如何运行我的两个 foreach 循环而不是一个

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

我正在运行这两个 foreach 循环以从我的数据库中获取数据,但是当我需要两者时,我只能让一个或另一个工作。

if ($stmt->rowcount() > 0) {
foreach($stmt as $row) {
$ResultsCounter++;
$htmlResult .= "<div style='margin-right:5px; width:280px' class='col-md-4 well text-center'>" .
"<h4>". $row['BusinessType'] . "</h4>"
."</div>";
}
} else{
$htmlResult .= "<h1 class='text-center'>Sorry no search results found please search again</h1>";
}

if ($stmt->rowcount() > 0) {
foreach($stmt as $row) {
$ResultsCounter++;
$htmlResult1.= "<li><a href='#'>" . $row['BusinessType'] . "</a></li>";
}
}

想法?

最佳答案

一次完成:

$htmlResult = '';
$htmlResult1 = '';

if ($stmt->rowcount() > 0) {
foreach($stmt as $row) {
$ResultsCounter++;
$htmlResult .= "<div style='margin-right:5px; width:280px' class='col-md-4 well text-center'>" .
"<h4>". $row['BusinessType'] . "</h4>"
."</div>";
$htmlResult1.= "<li><a href='#'>" . $row['BusinessType'] . "</a></li>";

}
} else{
$htmlResult .= "<h1 class='text-center'>Sorry no search results found please search again</h1>";
}

关于php - 如何运行我的两个 foreach 循环而不是一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33829945/

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