Php 如何运行两个foreach循环而不是一个

Php 如何运行两个foreach循环而不是一个,php,mysql,Php,Mysql,我正在运行这两个foreach循环来从数据库中获取数据,但是我只能在需要两者的时候让其中一个或另一个工作 if ($stmt->rowcount() > 0) { foreach($stmt as $row) { $ResultsCounter++; $htmlResult .= "<div style='margin-right:5px; width:280px' class='col-md-4 well te

我正在运行这两个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>";
}

您可以在两个循环之间重置迭代器光标,使您可以再次在其上循环。。。进入第一个循环?