getting individual record numbers?

17 posts by 3 authors in: Forums > CMS Builder
Last Post: December 8, 2009   (RSS)

By jimbly2 - November 30, 2009

Hi - I have a pages that is basically a table, into which I need to put conference topics from 4 years.

I have created the multi record thingy, but of course, it lists all the topics in a long list, whereas I need to seperate them out into each table cell.

My question is how do I say 'put record #1 here, put record #2 here, etc - rather than just
> Record Number: <?php echo $record['num'] ?>

...which lists the whole thing?

Thanks,

Jim

Re: [jimbly2] getting individual record numbers?

By Chris - November 30, 2009

Hi Jim,

While it's definitely possible to hard-code a custom layout using record numbers, if we can figure out a way to get CMS Builder to organize your records for you, you can save yourself a lot of work and potential future headaches.

Are there rules to how the records should be laid out in the table -- for example, ordered by date in a three column list with yearly header rows? Please explain how you'd like things laid out in your table.
All the best,
Chris

Re: [chris] getting individual record numbers?

By jimbly2 - November 30, 2009

Hi Chris,

thanks for responding - yu can see what I'm trying to do here:

http://www.madhouse1.com/clients/nawc/campaigns.php

I thought by putting each record number in each area it might work?



Thanks for your help,

Jim

Re: [jimbly2] getting individual record numbers?

By Chris - November 30, 2009 - edited: November 30, 2009

Hi Jim,

I'd create a section called "resolutions" with three fields: "content", "year", and "region". Then I'd start with the following code:

<?php
require_once "full path to viewer_functions.php";

list($resolutionsRecords,) = getRecords(array(
'tableName' => 'resolutions',
'orderBy' => 'year DESC, region'
));

?>

<table>
<tr>
<?php foreach ($resolutionsRecords as $record): ?>

<?php if ($record['year'] != @$currentYear): ?>
<?php if (@$currentYear): ?>
</tr><tr>
<?php endif ?>
<?php $currentYear = $record['year'] ?>
<?php $columnCount = 0 ?>
<td colspan="4">
Resolutions passed at the <?php echo htmlspecialchars($currentYear) ?> Conference:
</td>
</tr><tr>
<?php endif ?>

<?php $columnCount++ ?>
<td class="<?php echo $columnCount % 2 ? 'odd' : 'even' ?>">
<?php echo $record['content'] ?>
</td>
<?php endforeach ?>
</tr>
</table>

<?php if (!$resolutionsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>


Note that with this approach you'd want to be careful to make sure that there's a record for each region-year combination. I think this will be more managable than using record numbers.

I hope this helps! Please let me know if you have any questions.

EDIT: I added some code to alternate <td> classes so you can style your cells with alternating yellow and white backgrounds like in your example.
All the best,
Chris

Re: [chris] getting individual record numbers?

By jimbly2 - December 1, 2009

Hi Chris,

thanks for that - I created that section with those fields, but all I get is:

getRecords(resolutions): Unknown field 'title' in filenameFields or titleField options!

I thought this might be because it says 'Title, in the list order so I deleted it, but still gives an error.
Also - is this still going to link through to the main story - the page I sent you a link to is the 'list' page - so the content is, in effect the title, with a link to click through to the main article.

Jim

Re: [jimbly2] getting individual record numbers?

By jimbly2 - December 1, 2009

Hi - ok I have sorted the error by adding another field 'title' - which I guess I'd need anyway - but I'm totally confuddled as to how I can incorporate this into my layout, and make it link through to the full article in each case?
The client is so picky ( it's her layout!) that I can't deviate from it unfortunately.

Thanks

Jim

Re: [jimbly2] getting individual record numbers?

By Chris - December 1, 2009

Hi Jim,

How about using your 'title' field as the link text on your list page? Change this:

<?php echo $record['content'] ?>

to this:

<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>

You could also add "Region #" (as is displayed in your mockup) like this:

Region <?php echo $record['region'] ?><br />
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [jimbly2] getting individual record numbers?

By Chris - December 7, 2009

Hi Jim,

The idea here was to generate your layout while outputting records. You're generating the cells from PHP. Using a bit of PHP, it's possible to generate pretty much any layout you want. I think this is the best way to approach problems like these because your design will scale as new years are added and you won't have any problems with accidentally deleted records' numbers being hardcoded in your viewers.

If you want to go with this approach, but can't generate the layout you need, please post the differences and I'll show you how to change the PHP code to generate the layout you want.
All the best,
Chris

Re: [chris] getting individual record numbers?

By jimbly2 - December 7, 2009

Hi Chris,

thanks for that - yes I can see that approach makes more sense - I have posted a page which has my layout followed by what I'm getting from the code you posted - if it can be made to match up to the layout that would be great. I'm still not sure how we get all the 4 years one above the other like my layout - or do I create 4 different sections?



http://localhost/nawc/campaigns_list.php

Thanks for your help

Jim