lesson1_NML.zipAssignments iau3
All the present assignments maybe solved by mysql, or
by http://localhost/phpmyadmin.
It is always a good idea to test your SQL in the SQL client first, though.
That way you will not struggle with PHP and SQL errors at the same time.
This is work on the world database.
Write a select, showing all Scandinavian cities with
with more than 100000 inhabitants. They must be presented in
descending order by population.
Test the following two select declarations:
select name, countrycode, population from city where countrycode='DNK' and countrycode='NOR';
select name, countrycode, population from city where countrycode='SWE' or population > 100000;
Discuss the result. Is it meaningful? If yes, why? If not, why not?
Write a select, displaying all names of countries
with their respective populations, official languages, and the percentage of the
population that speaks that language.
Use some code similar to the following and place the declaration in that.
Test and change until it works
Hint: This is a join
of the tables country og countrylanguage
<?php
ini_set("include_path", ".:../globaLib:");
require_once "myTop.inc.php";
?>
<style type="text/css">
#tabel42, #tabel42 th, #tabel42 td { border: 1px solid blue; }
#tabel42 th { background-color: #cccccc; }
#tabel42 caption { font-weight: 700; caption-side: bottom; text-align: left; }
</style>
<?php
require_once "myNeck.inc.php";
?>
<!-- her kan indsættes content -->
<h1>Heureka!</h1>
<p>
Hvis vi har en <h1>Heureka!</h1> har
vores database-forbindelsesmodul virket. Hvis det
ikke virkede skulle vi forvente en fejlmeddelelse.
</p>
<div>
<?php
$sql = "select name, countrycode, population";
$sql .= " from city;";
$output = mysql_query($sql) or die ($sql . "<br />Fejl ved læsning");
print("<table id='tabel42'>\n");
while ($row = mysql_fetch_assoc($output)) {
printf("<tr><td>%s</td><td>%s</td><td>%d</td></tr>\n",
$row['name'], $row['countrycode'], $row['population']);
}
print("</table>\n");
?>
</div>
<?php
require_once "myBottom.inc.php";
?>