-
Notifications
You must be signed in to change notification settings - Fork 2
/
all_courses.php
67 lines (56 loc) · 1.41 KB
/
all_courses.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
header('Content-Type: application/json');
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "learners";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query to fetch courses with their details
$sql = "
SELECT
c.course_id,
c.title AS title,
c.instructor_name,
c.duration,
c.price,
c.release_date,
c.video_content, -- Updated: Renamed from content to video_content
c.description, -- New: Added description field
c.video_title, -- New: Added video_title field
c.prerequisite,
c.rating_count,
c.certificate,
c.intro_video, -- Updated: Intro video now stores video ID
c.image AS image,
c.stars,
c.discount,
cat.category_id,
cat.title AS category_title,
cat.image AS category_image,
cat.description AS category_description
FROM
courses c
INNER JOIN
categories cat
ON
c.category_id = cat.category_id;
";
// Execute query
$result = $conn->query($sql);
$popular_courses = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$popular_courses[] = $row;
}
}
// Output the data as JSON
echo json_encode($popular_courses);
// Close connection
$conn->close();
?>