Take your query from one of the previous problems and put it into a PHP page that displays the results using a table. (See next slides.)
Language | Percentage |
---|---|
English | 86.2 |
Spanish | 7.5 |
French | 0.7 |
$name = new PDO("dbprogram:dbname=database;host=server", username, password); $name->query("SQL query");
# connect to world database on local server
$db = new PDO("mysql:dbname=world;host=localhost", "traveler", "packmybags");
$db->query("SELECT * FROM countries WHERE population > 100000000;");
query
function returns rows that match a queryquery
$db = new PDO("dbprogram:dbname=database;host=server", username, password); $rows = $db->query("SQL query"); foreach ($rows as $row) { do something with $row; }
query
returns all result rows
$row["population"]
gives the value of the population
column<table>
,
<tr>
,
<td>
A 2D table of rows and columns of data (block element)
<table> <tr><th>Col 1</th><th>Col 2</th></tr> <tr><td>r1c1</td><td>r1c2 hello :-)</td></tr> <tr><td>r2c1 is very wide!</td><td>r2c2</td></tr> </table>
table
defines the overall tabletr
is each row, th
each header label, and td
each cell's datatable { border: 4px dotted blue; text-align: right; } td { border: 3px dashed red; width: 30%; padding: 10pt; }
Column 1 | Column 2 |
---|---|
1,1 | 1,2 okay |
2,1 real wide | 2,2 |