PHP Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.yearbookindex {
font: normal 95% verdana, helvetical, arial, sans-serif;
width: 500px;
border-collapse: collapse;
}
.name {
width: 200px;
}
.datepages {
text-align: right;
}
.odd {
background-color: #f7f6f3;
}
.even {
background-color: #DFDCCF;
}
.yearbookindex tr.even:hover, .yearbookindex tr.odd:hover {
background-color: rgb(174, 167, 134);
}
</style>
</head>
<body>
<?php
$test = array(
array('Albert, Joe', 1957, 14),
array('Albert, Joe', 1957, 17),
array('Albert, Joe', 1958, 12),
array('Albert, Joe', 1959, 18),
array('Swift, Mary', 1957, 14),
array('Swift, Mary', 1958, 14),
array('Swift, Mary', 1958, 16),
array('Swift, Mary', 1960, 22),
array('Cartwright, Angela', 2017, 212)
);
$sorted = array();
foreach($test as $entry){
if(!isset($sorted[$entry[0]])){
$sorted[$entry[0]] = array($entry[1] => $entry[2]);
} else if(isset($sorted[$entry[0]][$entry[1]])){
$sorted[$entry[0]][$entry[1]] .= ", $entry[2]";
} else {
$sorted[$entry[0]][$entry[1]] = $entry[2];
}
}
$rows = -1;
foreach ($sorted as $name => $years){
$temp = "<tr class='" . (++$rows % 2? 'even' : 'odd') . "'><td class='name'>$name</td><td class='datepages'>";
$count = count($years);
foreach ($years as $year => $pages){
$temp .= "$year/$pages";
if(!--$count){$temp .= '</td></tr>';}
else{$temp .= ' - ';}
}
$write[] = $temp;
}
?>
<table class="yearbookindex">
<tr>
<th class="name">Last Name, Other</th>
<th>Year(s) / Page(s)</th>
</tr>
<?php
echo implode("\n", $write);
?>
</table>
</body>
</html>
If the image links could come from the database, I'm sure it wouldn't be too hard to add them in to the listings.
Bookmarks