-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletter-index.php
76 lines (64 loc) · 2.4 KB
/
letter-index.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<link rel=stylesheet href="style.css" type="text/css">
<link rel="shortcut icon" href="flower.ico">
<title>Botanical Names - Useful Tropical Plants</title>
</head>
<body>
<?php
include 'functions.php';
include 'header.php';
include 'dbconnect.php';
echo "<h1>Index of botanical names</h1>\n";
echo '<p class="mainpageletters"><b>';
for ($char = 65; $char <= 90; $char++) {
echo "<a href=\"letter-index.php?letter=".chr($char)."\">".chr($char)."</a> ";
}
echo "</b></p>\n";
if (empty($_GET["letter"])) {
echo "<p>Click a letter to list all plants with the botanical names begining with that letter.</p>";
}
else
{
$key = $_GET["letter"];
if(preg_match('/^[A-Z]$/',$key)!=1) {
trigger_error("Invalid letter: \"".htmlspecialchars($key)."\", must be a single character.");
}
$pageno = empty($_GET["pageno"]) ? "0" : $_GET["pageno"];
if(!ctype_digit($pageno)) {
trigger_error("Invalid pageno: \"".htmlspecialchars($pageno)."\", must be a number.");
}
$amount = empty($_GET["amount"]) ? "100" : $_GET["amount"];
if(!ctype_digit($amount)) {
trigger_error("Invalid amount: \"".htmlspecialchars($amount)."\", must be a number.");
}
$q = "SELECT count(*) FROM `tropicalspecies` WHERE SUBSTRING(`Latin name`, 1, 1) = '$key'";
//echo htmlspecialchars($q);
$numPlantsRes = safe_query($db, $q);
$result = safe_query($db, "SELECT `Latin name`,`Common name` FROM `tropicalspecies` WHERE SUBSTRING(`Latin name`, 1, 1) = '$key' ORDER BY `Latin name` ASC LIMIT $pageno, $amount");
$numPlants = 0;
$numPlantsRow = mysqli_fetch_row($numPlantsRes);
if($numPlantsRow) {
$numPlants = $numPlantsRow[0];
}
if($numPlants) {
echo "<p>Showing ".mysqli_num_rows($result)." of $numPlants plants beginning with $key.</p>\n";
}
else {
echo "<p>Showing ".mysqli_num_rows($result)." plants beginning with $key.</p>\n";
}
$http_query = $_GET;
$http_query["amount"] = $amount;
nav_controls("letter-index.php", $http_query, $pageno, $amount, $numPlants);
output_table_query_limited($result, "Nothing", "tropicalspecies",null, "Latin name", "viewtropical.php", "id", -1, array("Latin name", "Common name"));
nav_controls("letter-index.php", $http_query, $pageno, $amount, $numPlants);
}
#mysqli_free_result($result);
include 'footer.php';
mysqli_close($db);
?>
</body>
</html>