I have an HTML tag here :
<span class="fa-stack fa-5x has-badge" >
<div class="badgesize">
<img src="badgeImages/1.png" alt="" >
</div>
</span> -->
Query used to retrieve info and store it in a variable :
$q4 = "SELECT TOP 3 b.BadgeName, b.BadgeImage FROM BadgeImageTable AS b
INNER JOIN employee_badge AS e
ON e.badge_id = b.BadgeID
WHERE e.employee_id = 2164
ORDER BY e.earned_on DESC ";
$stmt3=sqlsrv_query($conn,$q4);
if($stmt3==false)
{
echo 'error to retrieve info !! <br/>';
die(print_r(sqlsrv_errors(),TRUE));
}
In the image tag I am trying to echo an the image of a badge with some condition.
<span class="fa-stack fa-5x has-badge" >
<div class="badgesize">
<img src="
<?php
if($count = sqlsrv_num_rows($stmt3) > 0){
while($recentBadge = sqlsrv_fetch_array($stmt3)){
$result[] = $recentBadge;
}
if($count > 3){
$result = array_rand($result, 3);
}
foreach($result as $recentBadge){
echo
$recentBadge['BadgeName'],
'<img src="'.$recentBadge['BadgeImage'].'">',
'<br>'
;
}
} else {
echo 'no results';
}
?>
" alt="" >
</div>
</span>
Condition of above PHP:
I want to echo any three random images if the count is greater than 3, else echo whatever '$recentBadge' gives as the result.
Problem: I am unable to echo according to the above condition.
Whenever I try to echo a simple image without any condition(using below PHP), I am able to do so without any issue. So, I am able to fetch the image from the DB, problem lies with the conditional PHP.
<img src="<?php echo "".($badgerecent['BadgeImage']).""; ?>" >