How can i connection this code php with my sql to look like the sceen shoot disp
ID: 3833815 • Letter: H
Question
How can i connection this code php with my sql to look like the sceen shoot display under. thanks
Given the markup shown just below, write the PHP and the rest of the markup necessary to display the country names from the Countries table (id, name, capital, population) in a drop-down list. When the user clicks the submit button, the page should then display below the drop-down list the capital and population of the selected country. Assume that this page is called country.php
<!DOCTYPE html >
<html>
<head><title>Sample</title></head>
<body>
<form method=”POST” action=”country.php”>
Select a country <select>...</select>
<input type=”submit” value=”Submit”/>
</form>
</body>
Note: Use the Basic database connection algorithm provided on Page 461 to connect to Database from country.php script which is the following
<?php
try{
$connString = "mysql : host = localhost ; dbname=bookcrm ";
$user = "testuser";
$pass = "mypassword";
$pdo = new PDO($connString, $user, $pass);
$pdo ->setAttribute(PDO:: ATT_ERMODE, PDO :: ERMODE_EXCEPTION);
$sql = "select * from Categorie oder by CategoryName";
$result = $pdo ->query ($sql);
while ($row = result -> fetch()){
echo $row['ID] . " - " . $row['CategoryName'] . "<br/>";
}
$pdo = null;
}
catch (PDOException $e) {
die ($e ->getMessage ());
}
?>
here is the screen screen shot before clicking submit
here is the screent shoot after clicking sumit
What to turn in:
country.php
A screenshot of your countries table including at least five entries. Something similar to the following:
a Labs cscl 2006-90 In x Sample Zakaria 8888/labs/lab7/countr ocalhost EE Apps D2L Brightspace L E Microsoft My Account Other Bookmarks Select a country France SUBMITExplanation / Answer
SELECT c.name AS city_name, cou.name AS country_name FROM city c LEFT JOIN country cou ON c.countrycode = cou.code LEFT JOIN city c2 ON cou.capital = c2.id LEFT JOIN (SELECT countrycode, MAX(population) AS max_pop FROM city GROUP BY countrycode) t ON cou.code = t.countrycode WHERE c2.population = t.max_pop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.