-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
57 lines (52 loc) · 1.52 KB
/
index.php
File metadata and controls
57 lines (52 loc) · 1.52 KB
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
<!DOCTYPE html>
<html>
<body>
<?php
// Get access to MySQL Class
require_once(dirname(__FILE__).'/MySQL.class.php');
// Get MySQL connection
$conn = new MySQL('127.0.0.1','peoplecolour','root','ilovetocode');
// Get Rows of people
$query = 'select personid,firstname,lastname,email,dob from people2';
$rows = $conn->getRows($query);
// Get each persons Fav colours - Should be a function or a class to get colours..?
foreach ($rows as $key => $value) {
$query = "SELECT colour
FROM colours AS t1 JOIN fav_colours AS t2 ON t1.colourid = t2.colourid
WHERE personid = ".$value['personid'];
$colours = $conn->getRows($query);
$rows[$key]['fav_colours'] = implode(', ', array_map(function ($entry) {
return $entry['colour'];
}, $colours));
}
//print "<pre>";
//print_r($rows);
//print "</pre>";
?>
<!-- Create our Table -->
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">First Name</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Last Name</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Email</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Date of Birth</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Favourite Colours</font>
</td>
</tr>
<?php
foreach ($rows as $value) {
echo "<tr><td>".$value['firstname']."</td><td>".$value['lastname']."</td><td>".$value['email']."</td><td>".$value['dob']."</td><td>".$value['fav_colours']."</td></tr>";
}
?>
</table>
</body>
</html>