-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
42 lines (38 loc) · 1.29 KB
/
data.php
File metadata and controls
42 lines (38 loc) · 1.29 KB
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
<?php
include("top.html");
include("adventure_shared.php");
$command = $_GET["command"];
$sql = "SELECT DISTINCT continent FROM countries ORDER BY continent";//change this line of code to have a different query
print "<br>" . $sql . "<br>";//displays the sql query
$query = $db->prepare($sql); //prepares the query
$query->execute(); //runs the query
print_table($query);
$sql = "SELECT DISTINCT language FROM languages" . $command . " where code = CountryCode";//notice the ?
print "<br>" . $sql . "<br>";//displays the sql query
$query = $db->prepare($sql);//this is why prepare is useful
$query->execute(array("USA"));//runs the query
print_table($query);
$query->execute(array("AFG")); //rerun the query with new code
print_table($query);
$db = null;
function print_table($query){
print "<table border=1>\n";
$total = $query->columnCount();
for($counter = 0; $counter<$total; $counter++){
$meta = $query->getColumnMeta($counter);
print "<th>{$meta['name']}</th>\n";
$coln[$counter] = $meta['name'];
}
$rows = $query->fetchAll();
foreach($rows as $row){
print "<tr>\n";
for($counter = 0; $counter<$total; $counter++){
print "<td>{$row[$coln[$counter]]}</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
}
?>
</body>
</html>