-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-index.php
78 lines (64 loc) · 2.72 KB
/
common-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
77
78
<!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>Common Names - Useful Tropical Plants</title>
</head>
<body>
<?php
include 'functions.php';
include 'header.php';
include 'dbconnect.php';
echo "<h1>Index of common names</h1>\n";
echo '<p class="mainpageletters"><b>';
for ($char = 65; $char <= 90; $char++) {
echo "<a href=\"common-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 common names starting with that letter.</p>";
echo "<p>Not all plants have their common name in the database, and many plants have multiple common names.<br>Only one common name is given for each plant in the database.</p>";
$numPlantsRes = safe_query($db, "SELECT count(*) FROM `tropicalspecies` WHERE `Common name` <> ''");
$numPlants = 0;
$numPlantsRow = mysqli_fetch_row($numPlantsRes);
if($numPlantsRow) {
$numPlants = $numPlantsRow[0];
echo "<p>".$numPlants." plants in this database have common names.</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(preg_match('/^\d+$/',$pageno)!=1) {
trigger_error("Invalid pageno: \"".htmlspecialchars($pageno)."\", must be a number.");
}
$amount = empty($_GET["amount"]) ? 100 : $_GET["amount"];
if(preg_match('/^\d+$/',$amount)!=1) {
trigger_error("Invalid amount: \"".htmlspecialchars($amount)."\", must be a number.");
}
$numPlantsRes = safe_query($db, "SELECT count(*) FROM `tropicalspecies` WHERE SUBSTRING(`Common name`, 1, 1) = '$key'");
$result = safe_query($db, "SELECT `Latin name`,`Common name` FROM `tropicalspecies` WHERE SUBSTRING(`Common name`, 1, 1) = '$key' ORDER BY `Common name` ASC LIMIT $pageno, $amount");
$numPlantsRow = mysqli_fetch_row($numPlantsRes);
if($numPlantsRow) {
$allcount = $numPlantsRow[0];
}
echo "<p>Showing ".mysqli_num_rows($result)." of ".$allcount." plants beginning with $key</p>";
$http_query = $_GET;
$http_query["amount"] = $amount;
nav_controls("common-index.php", $http_query, $pageno, $amount, $allcount);
output_table_query_limited($result, "Nothing", "tropicalspecies",null, "Common name", "viewtropical.php", "id", -1, array("Common name", "Latin name"), "Latin name");
nav_controls("common-index.php", $http_query, $pageno, $amount, $allcount);
}
#mysql_free_result($result);
include 'footer.php';
mysqli_close($db);
?>
</body>
</html>