-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchDisplayChannel.php
112 lines (93 loc) 路 2.5 KB
/
fetchDisplayChannel.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
require_once('auth.php');
$genres = array(
'e' => 'Entertainment',
'f' => 'Family',
'i' => 'Information',
'm' => 'Movies',
'n' => 'News/Business',
'o' => 'Old TV Shows',
's' => 'Sci-Fi',
't' => 'Sports'
);
// database connection and boring stuff
$dbc = mysqli_connect('localhost', 'root', '123456', 'channelwatchdb')
or die('error connecting to the database');
// first, get all movies then restrict
$query = "SELECT * FROM channeltbl";
// get the query string
if (isset($_POST['title'])){
$title = $_POST['title'];
// if there is a specified title
if (!empty($title)) {
if ($_POST['criteria'] == 'wt') {
$query .= " WHERE ch_title LIKE '%$title%'";
} else if ($_POST['criteria'] == 'sw') {
$query .= " WHERE ch_title LIKE '$title%'";
} else if ($_POST['criteria'] == 'et') {
$query .= " WHERE ch_title = '$title'";
}
}
// if there is a genre
if ($_POST['genre'] != 'a') {
if (empty($title))
$query .= " WHERE ";
else
$query .= " AND ";;
$genre = $_POST['genre'];
$query .= " ch_genre = '$genre'";
}
// since it will be grouped
$query .= ' ORDER BY';
// if group by genre
if (isset($_POST['group_by_genre'])) {
$query .= ' ch_genre,';
}
// order by title or price
if ($_POST['order_by'] == 'ch_title') {
$query .= ' ch_title';
} else if ($_POST['order_by'] == 'ch_price') {
$query .= ' ch_price DESC';
}
}
$result = mysqli_query($dbc, $query)
or die('error querying');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Shaw</title>
</head>
<body>
<h1 align="center">Shaw Channel</h1>
<h2 align="center">Title Search Results</h2>
<form action="addOrderChannel.php" method="post">
<table align="center" border="1">
<tr>
<th>Title</th>
<th>Id</th>
<th>Logo</th>
<th>Genre</th>
<th>Price</th>
<th>Add to cart</th>
</tr>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<tr>
<td><?php echo $row['ch_title']?></td>
<td><?php echo $row['ch_id']?></td>
<td><img src="logos/<?php echo $row['ch_logo']?>" alt="channel logo" width="80" height="45"></td>
<td><?php echo $genres[$row['ch_genre']]?></td>
<td><?php echo $row['ch_price']?></td>
<td>
<input type="checkbox" name="channels[]" value="<?php echo $row['ch_id']?>">
</td>
</tr>
<?php endwhile; ?>
</table>
<p align="center">
<input type="submit" value="Submit"> <input type="reset" name="clear">
</p>
</form>
</body>
</html>
<?php mysqli_close($dbc); ?>