-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab10.php
204 lines (153 loc) · 6.52 KB
/
Lab10.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
//Fill this place
//****** Hint ******
//connect database and fetch data here
$_mysqli = mysqli_connect('localhost','root','');
mysqli_select_db($_mysqli,'travel');
//如果需要手动导入的代码
//$_sql = file_get_contents('sql/travel-small.sql');
//$_arr = explode(';',$_sql);
//set_time_limit(0);
//foreach ($_arr as $_value){
// $_mysqli -> query($_value.';');
//}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chapter 14</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/captions.css" />
<link rel="stylesheet" href="css/bootstrap-theme.css" />
</head>
<body>
<?php include 'header.inc.php'; ?>
<!-- Page Content -->
<main class="container">
<div class="panel panel-default">
<div class="panel-heading">Filters</div>
<div class="panel-body">
<form action="Lab10.php" method="get" class="form-horizontal">
<div class="form-inline">
<select name="continent" class="form-control">
<option value="0">Select Continent</option>
<?php
//Fill this place
//****** Hint ******
//display the list of continents
$sqlContinentName = "select * FROM Continents";
$result = $_mysqli -> query($sqlContinentName);
while($row = $result->fetch_assoc()) {
echo '<option value=' . $row['ContinentCode'] . '>' . $row['ContinentName'] . '</option>';
}
?>
</select>
<select name="country" class="form-control">
<option value="0">Select Country</option>
<?php
//Fill this place
//****** Hint ******
/* display list of countries */
$sqlCountryName = "select * FROM Countries";
$result = $_mysqli -> query($sqlCountryName);
while($row = $result->fetch_assoc()) {
echo '<option value=' . $row['ISO'] . '>' . $row['CountryName'] . '</option>';
}
?>
</select>
<input type="text" placeholder="Search title" class="form-control" name=title>
<button type="submit" class="btn btn-primary">Filter</button>
</div>
</form>
</div>
</div>
<ul class="caption-style-2">
<?php
//Fill this place
//****** Hint ******
/* use while loop to display images that meet requirements ... sample below ... replace ???? with field data*/
error_reporting(0);
// $sqlImageDetails = "select * FROM ImageDetails";
// $result = $_mysqli -> query($sqlImageDetails);
// echoPics($result);
$choosedContinent = $_GET["continent"];
$choosedCountry = $_GET["country"];
//以下代码用于测试
//echo $choosedContinent;
//echo $choosedCountry;
// if($choosedContinent != '0' && $choosedCountry === "0"){
// echo "true";
// }else{
// echo "false";
// }
// if($choosedContinent === "0" && $choosedCountry != '0'){
// echo "true";
// }else{
// echo "false";
// }
// if($choosedContinent === "0" && $choosedCountry === "0"){
// echo "true";
// }else{
// echo "false";
// }
// if($choosedContinent != '0' && $choosedCountry != '0'){
// echo "true";
// }else{
// echo "false";
// }
if($choosedContinent != '0' && $choosedCountry === "0"){
$sqlImageDetails = "select * FROM ImageDetails WHERE ContinentCode = '".$choosedContinent."'";
$result = $_mysqli -> query($sqlImageDetails);
echoPics($result);
}
if($choosedContinent === "0" && $choosedCountry != '0'){
$sqlImageDetails = "select * FROM ImageDetails WHERE CountryCodeISO = '".$choosedCountry."'";
$result = $_mysqli -> query($sqlImageDetails);
echoPics($result);
}
if(($choosedContinent === "0" && $choosedCountry === "0")||($choosedContinent == "" && $choosedCountry == "")){
$sqlImageDetails = "select * FROM ImageDetails";
$result = $_mysqli -> query($sqlImageDetails);
echoPics($result);
}
if($choosedContinent != '0' && $choosedCountry != '0'){
$sqlImageDetails = "select * FROM ImageDetails WHERE CountryCodeISO = '{$choosedCountry}' and ContinentCode ='{$choosedContinent}'";
$result = $_mysqli -> query($sqlImageDetails);
echoPics($result);
}
function echoPics($arg){
while ($row = $arg->fetch_assoc()){
echo '
<li>
<a href="detail.php?id='.$row['ImageID'].'" class="img-responsive">
<img src="images/square-medium/'.$row['Path'].'" alt="'.$row['Title'].'">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<p>'.$row['Description'].'</p>
</div>
</div>
</a>
</li>
';
}
}
?>
</ul>
</main>
<footer>
<div class="container-fluid">
<div class="row final">
<p>Copyright © 2017 Creative Commons ShareAlike</p>
<p><a href="#">Home</a> / <a href="#">About</a> / <a href="#">Contact</a> / <a href="#">Browse</a></p>
</div>
</div>
</footer>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>