| Path : /home/vishqocm/pcib.in/ |
| Current File : /home/vishqocm////pcib.in/relatedcourses.php |
<!-- Related Courses -->
<?php if ($related_result && mysqli_num_rows($related_result) > 0): ?>
<div class="related-courses section-padding bg-light">
<div class="container">
<h3 class="section-title text-center mb-5">Related Courses You May Like</h3>
<div class="row">
<?php while ($related = mysqli_fetch_assoc($related_result)): ?>
<div class="col-lg-4 col-md-6 mb-4">
<div class="course-card h-100">
<?php
// Check all possible image paths in order of preference
$image_path_1 = 'assets/img/courses/' . $related['id'] . '.jpg';
$image_path_2 = 'assets/images/courses/' . $related['id'] . '.jpg';
$image_path_3 = isset($related['image']) ? $related['image'] : '';
$image_path_4 = 'assets/img/courses/default.jpg';
$image_path_5 = 'assets/images/course-placeholder.jpg';
$image_path_6 = 'https://placehold.co/600x400/4f46e5/ffffff?text=' . urlencode(substr($related['title'], 0, 20));
// Check which image exists
if (file_exists($image_path_1)) {
$related_image_url = $image_path_1;
} elseif (file_exists($image_path_2)) {
$related_image_url = $image_path_2;
} elseif (isset($image_path_3) && !empty($image_path_3) && file_exists($image_path_3)) {
$related_image_url = $image_path_3;
} elseif (file_exists($image_path_4)) {
$related_image_url = $image_path_4;
} elseif (file_exists($image_path_5)) {
$related_image_url = $image_path_5;
} else {
$related_image_url = $image_path_6;
}
?>
<div class="course-card-header">
<div class="course-image">
<img src="<?php echo $related_image_url; ?>" alt="<?php echo htmlspecialchars($related['title']); ?>" class="course-img">
<div class="course-overlay">
<a href="course-details.php?id=<?php echo $related['id']; ?>" class="btn btn-primary btn-sm">View Details</a>
</div>
</div>
<?php
// Display category badge
if (isset($related['category'])) {
// Take the first category if multiple exist
$category = $related['category'];
if (strpos($category, ',') !== false) {
$categories = explode(',', $category);
$category = trim($categories[0]);
}
// Determine badge color based on category
$category_colors = [
'web development' => 'primary',
'design' => 'info',
'marketing' => 'success',
'programming' => 'danger',
'business' => 'warning',
'data science' => 'secondary',
'mobile development' => 'dark'
];
$category = strtolower($category);
$badge_color = isset($category_colors[$category]) ? $category_colors[$category] : 'primary';
echo '<span class="course-badge bg-' . $badge_color . '">' . htmlspecialchars(ucwords($category)) . '</span>';
}
?>
</div>
<div class="course-card-body">
<h5 class="course-title">
<a href="course-details.php?id=<?php echo $related['id']; ?>"><?php echo htmlspecialchars($related['title']); ?></a>
</h5>
<p class="course-desc"><?php echo htmlspecialchars(substr($related['description'], 0, 100)); ?>...</p>
<div class="course-meta">
<?php if (isset($related['instructor_name'])): ?>
<div class="course-instructor">
<i class="fas fa-user-tie"></i> <?php echo htmlspecialchars($related['instructor_name']); ?>
</div>
<?php endif; ?>
<?php if(isset($related['duration'])): ?>
<div class="course-duration">
<i class="far fa-clock"></i> <?php echo htmlspecialchars($related['duration']); ?>
</div>
<?php endif; ?>
</div>
</div>
<div class="course-card-footer">
<div class="course-rating">
<?php
$rating = isset($related['avg_rating']) ? floatval($related['avg_rating']) : rand(35, 50) / 10;
$full_stars = floor($rating);
$half_star = $rating - $full_stars >= 0.5;
$empty_stars = 5 - $full_stars - ($half_star ? 1 : 0);
for ($i = 0; $i < $full_stars; $i++): ?>
<i class="fas fa-star"></i>
<?php endfor;
if ($half_star): ?>
<i class="fas fa-star-half-alt"></i>
<?php endif;
for ($i = 0; $i < $empty_stars; $i++): ?>
<i class="far fa-star"></i>
<?php endfor; ?>
<span class="rating-text"><?php echo number_format($rating, 1); ?></span>
<span class="rating-count">(<?php echo isset($related['review_count']) ? intval($related['review_count']) : '0'; ?>)</span>
</div>
<div class="course-price">
<?php if (isset($related['price']) && $related['price'] > 0): ?>
<?php if (isset($related['discount_price']) && $related['discount_price'] > 0 && $related['discount_price'] < $related['price']): ?>
<span class="price-tag discount">
<span class="current-price">₹<?php echo number_format($related['discount_price'], 2); ?></span>
<span class="old-price">₹<?php echo number_format($related['price'], 2); ?></span>
</span>
<?php else: ?>
<span class="price-tag">₹<?php echo number_format($related['price'], 2); ?></span>
<?php endif; ?>
<?php else: ?>
<span class="price-tag free">Free</span>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php endif; ?>