I'm trying to create an alphabetical listing of items that have been stored as DataObjects using the DOM, so that I get something like: http://www.hans.org/directory/
I need to have it separated in two columns (A to M, and N to Z), so was thinking of having 2 functions that each return a range of entries, and then perform some function in the view to control what gets displayed.
However, as SS doesn't like PHP in the view templates, does anyone know how to do this in the controller? Would I need to store each character as it's own array with the returned array? Or is there a more straightforward way of doing it?
If I was writing this in (fugly) PHP the first function would run something like:
$qry = "SELECT title, LEFT(title, 1) AS first_char FROM resourceobjects
WHERE UPPER(LEFT(title, 1)) BETWEEN 'A' AND 'M' ORDER BY title";
$result = mysql_query($qry);
$current_char = '';
while ($row = mysql_fetch_assoc($result)) {
if ($row['first_char'] != $current_char) {
$current_char = $row['first_char'];
echo '<h2>' . strtoupper($current_char) . '</h2>';
}
echo '<p>' . $row['title'] . '</p>';
}
Any help much appreciated :)