$latestRes = mysqli_query($con, '
SELECT cr.*, crc.cat_name AS subcategory, crmc.cat_name AS category,
(
SELECT COUNT(*) FROM orders AS o
WHERE o.car_id = cr.id
) AS totalBookings
FROM carrental AS cr
LEFT JOIN carrentalcat AS crc ON crc.id = cr.cat_id
LEFT JOIN carrental_main_cat AS crmc ON crmc.id = cr.main_cat_id
WHERE cr.isFeature = "Y"
ORDER BY rand() LIMIT 4
');
?>
if($latestRes && mysqli_num_rows($latestRes) > 0): ?>
while($latestRow = mysqli_fetch_object($latestRes)): ?>
$id = $latestRow->id;
$car_name = stripslashes($latestRow->car_name);
if(strpos($latestRow->img, '/images') !== false){
$imgPath = '.'.stripslashes($latestRow->img);
}else {
$imgPath = './images/cars/'.stripslashes($latestRow->img);
}
$carUrl = makePermaLink($car_name).'-'.$id.'.php';
$img_title = stripslashes($latestRow->img_title);
?>
endwhile; ?>
endif; ?>