Show 1 record in detail, rest in a list

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 30, 2009   (RSS)

By sidcam - March 7, 2009

Question. Is there a way to display the latest record in a table on one part of the page (in detail form) and then display the rest of the records in a list starting with the second newest record? Basically I would like to do what newspapers do and have the latest article in a category show up at the top of the page with photos, a summary, larger text, etc. and then have a list of older articles below it with just the title and a link.

I guessing this will require two calls to the same table (one for the details, one for this list) and I'm reading that can be done, but I don't know how to make the list exclude the first record.

Thanks, Sid

Re: [sidcam] Show 1 record in detail, rest in a list

By Dave - March 9, 2009

Hi Sid,

There's a few ways to do that. The simplest is probably to use two viewers. For the first one, add this code to limit the results to just one record:
'limit' => 1,

To the next viewer, add this to start at the second record:
'offset' => 1,

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [sidcam] Show 1 record in detail, rest in a list

By ross - April 30, 2009

Hi there.

As long as you put the code for Table A first, you can start using variables from it immediately.

So when you setting up the code for Table B, you can use

$TableA-news-storiesRecord['SOMETHING']

in the WHERE clause. It's always good practice to escape any values you test in a MySQL statement though, so something like this would work better:

'where' => 'title = "'. mysql_real_escape_string( $TableA-news-storiesRecord['SOMETHING'] ) .'"',

You'll probably need to play around with that a bit but that's the jist of it all.

Let me know what you think :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/