Show 1 record in detail, rest in a list

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

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: [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/