 |

steve_e
User
Mar 29, 2008, 2:55 AM
Post #1 of 3
(210 views)
Shortcut
|
|
List page categorized by field
|
Can't Post
|
|
I'd like to have the records of the list (or index?) page appear sorted by a field from the record. So, for example, if the section gave details of cats, with age, name, address and breed as fields, I would like to list all Manx cats, followed by all tabby cats or whatever. But I'd only like the field label (eg 'Manx') to appear once, as a heading. How would I set the logic for that? I've tried a couple of different 'for each' and 'if' variations but my coding skills are pretty minimal...
|
|
|  |
 |

Dave
Staff
/ Moderator

Mar 29, 2008, 4:44 AM
Post #2 of 3
(206 views)
Shortcut
|
|
Re: [steve_e] List page categorized by field
[In reply to]
|
Can't Post
|
|
Hi Steve, Sort by breed first, then whatever field you want to sort on next. Then... Add this bit of code to your list records block:
<?php foreach ($listRows as $record): ?> ... <?php if ($record['breed'] != @$lastBreed): ?> <h1><?php echo $record['breed'] ?></h1> <?php $lastBreed = $record['breed']; endif ?> ... <?php endforeach ?>
Basically, we just keep a copy of the breed from the last record in $lastBreed, and if it changes we show a heading. Hope that helps! Let me know if you need any more assistance with that. Dave Edis - Senior Developer interactivetools.com
|
|
|  |
 |

steve_e
User
Mar 29, 2008, 7:45 AM
Post #3 of 3
(204 views)
Shortcut
|
|
Re: [Dave] List page categorized by field
[In reply to]
|
Can't Post
|
|
Hi Dave - Excellent, thanks very much! Best wishes, Steve.
|
|
|  |
|