Detail viewer / related table

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 27, 2012   (RSS)

Re: [Toledoh] Detail viewer / related table

By Jason - April 27, 2012

Hi Tim,

The easiest way to do this would be to first get an array of all your beer records, where the index of your array is the record num of the beer record.

You can do that like this:

<?php

list($beerRecords, ) = getRecords(array(
'tableName' => 'our_beers',
'allowSearch' => false,
));


$beerNumToRecord = array_groupBy($beerRecords, 'num');

?>


Next, you can set up a foreach loop to output each one of your taps, 1 at a time. In this example code, we assume that you are using 4 taps (tap_1 - tap_4). This can be adjusted by changing the value of $numberOfTaps

EXAMPLE:



<?php $numberOfTaps = 4; ?>

<?php foreach (range(1, $numberOfTaps) as $tapNum): ?>
<?php $tapField = "tap_$tapNum"; ?>

<?php if (!@$manly_tapsRecord[$tapField]) { continue; } ?>

Tap <?php echo $tapField;?> : <?php echo $manly_tapsRecord["$tapField:label"]; ?>

<?php
//get related beer record
$beer = $beerNumToRecord[$manly_tapsRecord[$tapField]];
?>

<?php
//ouput beer information here
?>

<?php endforeach ?>


So in this foreach loop, $beer is the our_beer record that was selected for the tap that is currently being output.

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/

Re: [Jason] Detail viewer / related table

By Toledoh - April 27, 2012

Wow - perfect!

Why didn't I think of that [shocked]
Cheers,

Tim (toledoh.com.au)