I have an HTML tag here :
The output from your code was putting <img>
tags inside the src attribute of the tag.
That by definition doesn't work in HTML. If everything else was right, this should work:
<?php
function get_random_elements( $array,$limit = 0 ) {
shuffle($array);
if ( $limit > 0 ) {
$array = array_splice($array, 0, $limit);
}
return $array;
}
function render_images() {
global $stmt3;
$output = '';
if ($count = sqlsrv_num_rows($stmt3) > 0) {
while ($recentBadge = sqlsrv_fetch_array($stmt3)) {
$result[] = $recentBadge;
}
if ($count > 3) {
$result = get_random_elements(result, 3);
}
foreach ($result as $recentBadge) {
$output .= $recentBadge['BadgeName'];
$output .= '<img src="' . $recentBadge['BadgeImage'] . '" alt="">';
$output .= '<br>';
}
} else {
$output = 'no results';
}
return $output;
}
?>
<span class="fa-stack fa-5x has-badge" >
<div class="badgesize">
<?php echo render_images(); ?>
</div>
</span>
As a tip: please try to keep your code separated, the logic separated from the view.