Pulling in first record from each category (set by list/radio buttons)

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 24, 2013   (RSS)

By Kittybiccy - September 17, 2013

Hi there,

I'm working on a new site and wondered if the following was possible and if so, how?

I have a site for a theatre co. where we will be listing all shows under one record and I'll then be using a list and radio buttons to display the records on designated pages. I've done this before to get a site to display all upcoming shows on one page and all archived shows on another which I'll be doing here but what I also wanted to do with this one is to get the list page to display the first record for each type of show 'spring', 'spellbound', etc

So there are 6 radio buttons:
PANTOMIME - SHOWSTOPPERS - AUTUMN SHOW - SPELLBOUND - SPRING SHOW - ARCHIVE

And on the main list page I would like the first record for each type, except the archived shows, to be displayed. Here is the HTML page so you can see what I mean!
http://www.fromemtc.co.uk/NEW/forthcoming-shows-in-frome.html

Is this possible? Thanks!

By Jason - September 17, 2013

Hi,

Sure.  What you can do is use the getListOptions() function to loop though all your different show types, and then use getRecords to get a single record for each one.

In this example, we assume that you have a section called "shows", and that your radio button list is called "type"

<?php foreach (getListOptions("shows", "type") as $value => $label): ?>

  <?php
    list($showRecord, ) = getRecords(array(
      'tableName'    =>  'shows',
      'allowSearch'  =>  false,
      'limit'        =>  1,
      'where'        =>  "type = '".mysql_escape($value)."'",
    ));
    
    if (!$showRecord) { continue; } // skip if no record was found
    $show = $showRecord[0];
    
  ?>
  
  // output $show record here.


<?php endforeach ?>

Hope this helps get you started

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Kittybiccy - September 23, 2013

Hi Jason,

Thanks for this. What would I then need for each top record per section to be displayed as per that html page I linked to ie. the top record for x show type - the top record for y show type - the top record for z show type etc .

One row of the 5 top records: http://www.fromemtc.co.uk/NEW/forthcoming-shows-in-frome.html

Do you think this would be easier if we got you guys to look into it and could you tell me how much that would cost?

Hannah

By Jason - September 24, 2013

Hi Hannah,

This code can be embedded in your HTML where you want the show records to be displayed.  Each iteration of the loop should output the HTML for a single one of your show "boxes".  If you would like us to step in and implement this for you, we can certainly do that.  If you could please email consulting@interactivetools.com we can go over some options.   As this looks like a pretty simple integration, I would expect the cost to be quite low.

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/