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: [Dave] Show 1 record in detail, rest in a list

By sidcam - April 28, 2009

Dave-

I need to display content from two Tables on one page. However the record displayed from Table B is dependent on a drop down field selection of the record used from Table A. Is it possible to do relational stuff like that? (Basically the content of Table A is controlled by the user and the content of Table B is controlled by the Admin).

EXAMPLE: CALL A RECORD IN TABLE A

list($TableA-news-storiesRecords, $TableA-news-storiesMetaData) = getRecords(array(
'tableName' => 'TableA-news-stories',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$TableA-news-storiesRecord = @$TableA-news-storiesRecords[0]; // get first record

THEN A RECORD IN TABLE B IS CALLED THAT'S DEPENDENT ON THE OUTPUT OF TABLE A

list($TableB-adsRecords, $TableB-adsMetaData) = getRecords(array(
'tableName' => 'TableB-ads',
'where' => 'Title = "CONTENT OF A FIELD IN TABLE A"',
'limit' => '1',
));
$TableB-adsRecord = @$TableB-adsRecords[0]; // get first record

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/