From 9328fc6edfb247a8f979b40eb45266875060e063 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Thu, 27 Oct 2016 02:31:03 -0400 Subject: [PATCH] Mostly done ch11pr02 Needs images displayed on all selections Needs filter selection to actually do anything --- chapter11/project2/browse-images.php | 76 ++++++++++++++++++- chapter11/project2/databaseLogin.inc.php | 2 +- .../includes/travel-left-rail.inc.php | 22 +++++- 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/chapter11/project2/browse-images.php b/chapter11/project2/browse-images.php index bbbf6c6..d64888a 100644 --- a/chapter11/project2/browse-images.php +++ b/chapter11/project2/browse-images.php @@ -1,7 +1,59 @@ <?php + header('Content-Type: text/html; charset=ISO-8859-1'); + + # Initialize database connection variables specific to this page. + include "databaseLogin.inc.php"; + + include "databaseConnect.inc.php"; + include "sqlStatements.inc.php"; + + # Connect to DB. + #ConnectViaMySQLi($host, $DBuser, $DBpassword, $database); + $pdo = ConnectViaPDO($host, $DBuser, $DBpassword, $database, $DBport); + + + # Initially load databases. + # Load GeoContinents. + $sql = SQLSelectOrder("*", "GeoContinents", "ContinentName"); + $sqlGeoContinents = $pdo->query($sql); + + # Load GeoCountries. + $sql = SQLSelectOrder("*", "GeoCountries", "CountryName"); + $sqlGeoCountries = $pdo->query($sql); + + # Load GeoCities. + $sql = SQLSelectOrder("*", "GeoCities", "AsciiName"); + $sqlGeoCities = $pdo->query($sql); + + # Load TravelImage. + $sql = SQLSelect("*", "TravelImage"); + $sqlTravelImage = $pdo->query($sql); + + # Load TravelImageDetails. + $sql = SQLSelect("*", "TravelImageDetails"); + $sqlTravelImageDetails = $pdo->query($sql); + + + # Merge Countries and Image Details. + # Only returns countries with valid image data. + $sql = "SELECT DISTINCT GeoCountries.CountryName + FROM GeoCountries, TravelImageDetails + WHERE GeoCountries.FipsCountryCode = TravelImageDetails.CountryCodeISO;"; + $sqlCountriesMatch = $pdo->query($sql); + + $sql = "SELECT DISTINCT GeoCountries.CountryName, GeoCountries.ISONumeric + FROM GeoCountries, TravelImageDetails + WHERE GeoCountries.FipsCountryCode = TravelImageDetails.CountryCodeISO;"; + $sqlCountriesMatch2 = $pdo->query($sql); + + # Merge Cities and Image Details. + # Only returns cities with valid image data. + $sql = "SELECT DISTINCT GeoCities.AsciiName + FROM GeoCities, TravelImageDetails + WHERE GeoCities.GeoNameID = TravelImageDetails.CityCode;"; + $sqlCitiesMatch = $pdo->query($sql); - ?> <!DOCTYPE html> @@ -32,13 +84,29 @@ <div class="form-group" > <select class="form-control" name="city"> <option value="0">Filter by City</option> - + <?php + if ($sqlCitiesMatch) { + while ($row = $sqlCitiesMatch->fetch()) { + echo "<option value=" . $row['GeoNameID'] . ">" . $row['AsciiName'] . "</option>"; + } + } else { + echo "<option value='-1'>No Cities to display.</option>"; + } + ?> </select> </div> <div class="form-group"> <select class="form-control" name="country"> - <option value="ZZZ">Filter by Country</option> - + <option value="0">Filter by Country</option> + <?php + if ($sqlCountriesMatch2) { + while ($row = $sqlCountriesMatch2->fetch()) { + echo "<option value=" . $row['ISONumeric'] . ">" . $row['CountryName'] . "</option>"; + } + } else { + echo "<option value='-1'>No Countries to display.</option>"; + } + ?> </select> </div> <button type="submit" class="btn btn-primary">Filter</button> diff --git a/chapter11/project2/databaseLogin.inc.php b/chapter11/project2/databaseLogin.inc.php index 611c747..7b32b32 100644 --- a/chapter11/project2/databaseLogin.inc.php +++ b/chapter11/project2/databaseLogin.inc.php @@ -1,7 +1,7 @@ <?php #$host = "localhost"; $host = "127.0.0.1"; - $database = "bookcrm"; + $database = "travels"; $DBport = ""; #$DBport = "3306"; $DBuser = "root"; diff --git a/chapter11/project2/includes/travel-left-rail.inc.php b/chapter11/project2/includes/travel-left-rail.inc.php index 8d35c3f..19b581d 100644 --- a/chapter11/project2/includes/travel-left-rail.inc.php +++ b/chapter11/project2/includes/travel-left-rail.inc.php @@ -16,14 +16,28 @@ <div class="panel panel-info"> <div class="panel-heading">Continents</div> <ul class="list-group"> - - + <?php + if ($sqlGeoContinents) { + while ($row = $sqlGeoContinents->fetch()) { + echo "<li><a href=#>" . $row['ContinentName'] . "</a></li>"; + } + } else { + echo "<li>No Continents to display.</li>"; + } + ?> </ul> </div> <!-- end continents panel --> <div class="panel panel-info"> <div class="panel-heading">Popular Countries</div> <ul class="list-group"> - - + <?php + if ($sqlCountriesMatch) { + while ($row = $sqlCountriesMatch->fetch()) { + echo "<li><a href=#>" . $row['CountryName'] . "</a></li>"; + } + } else { + echo "<li>No Countries to display.</li>"; + } + ?> </ul> </div> <!-- end countries panel --> \ No newline at end of file -- GitLab