I am running these two foreach loops to get data from my database, however I can only get one or the other to work when I need both to do so.
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>";
}
}
Thoughts?
Just do it in one shot :
$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>";
}