combining two sections

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 13, 2011   (RSS)

By rez - October 12, 2011 - edited: October 12, 2011

I have slideshow pics in one section and some testimonials in another. For each slide, I want to add a random testimonial.

something like:

// load records
list($home_slideshowRecords, $home_slideshowMetaData) = getRecords(array(
'tableName' => 'home_slideshow',
));
list($slidequotesRecords, $slidequotesMetaData) = getRecords(array(
'tableName' => 'testimonials',
'orderBy' => "RAND()",
'limit' => $home_slideshowMetaData['totalRecords'],
));

?><<?php ?>?xml version="1.0" encoding="utf-8"?>
<Slideshow>
<items>
<?php foreach ($home_slideshowRecords as $home_slideshowRecord): ?>
<?php foreach ($home_slideshowRecord['slide'] as $upload): ?>
<item>
<thumbnailPath><?php echo $upload['thumbUrlPath'] ?></thumbnailPath>
<largeImagePath><?php echo $upload['urlPath'] ?></largeImagePath>
<fullScreenImagePath><?php echo $upload['urlPath'] ?></fullScreenImagePath>
<testimonial><![CDATA[&nbsp;<?php echo A SLIDESHOW QUOTE HERE?>]]></testimonial>
</item>
<?php endforeach ?>
<?php endforeach ?>
</items>
</Slideshow>


The problem I am having (if my list code is correct and making a number of testimonials = to the number of images) is that i dont know how to set up a counter or keep track of which testimonial is showing because they arent numbered (if thats the best way?) Or are they numbered because they are in the list? Or do they have to be added to a new array? ... always confused in this area.

thanks for your help.

Re: [robin] combining two sections

By rez - October 12, 2011 - edited: October 12, 2011

hmm. So the records are already numbered in the $slidequotesRecords ? This is the type of thing I dont understand yet but anyway, I'm getting the string, "Array" for each result instead of a testimonial. I am assuming i have to make i=1 or 0 first?

list($home_slideshowRecords, $home_slideshowMetaData) = getRecords(array(
'tableName' => 'home_slideshow',
));
list($slidequotesRecords, $slidequotesMetaData) = getRecords(array(
'tableName' => 'testimonials',
'orderBy' => "RAND()",
'limit' => $home_slideshowMetaData['totalRecords'],
));

?><<?php ?>?xml version="1.0" encoding="utf-8"?>
<Slideshow>
<items>
<?php $i = 0; ?>
<?php foreach ($home_slideshowRecords as $home_slideshowRecord): ?>
<?php foreach ($home_slideshowRecord['slide'] as $upload): ?>
<item>
<thumbnailPath><?php echo $upload['thumbUrlPath'] ?></thumbnailPath>
<largeImagePath><?php echo $upload['urlPath'] ?></largeImagePath>
<fullScreenImagePath><?php echo $upload['urlPath'] ?></fullScreenImagePath>
<title><![CDATA[&nbsp;<?php echo $home_slideshowRecord['title'] ?>]]></title>
<description><![CDATA[&nbsp;<?php echo @$slidequotesRecords[$i++]; ?>]]></description>
</item>
<?php endforeach ?>
<?php endforeach ?>
</items>
</Slideshow>

Re: [rez] combining two sections

By robin - October 13, 2011

Hey Res,

Ah, I forgot to mention you need to put the field name also. I'm not sure what you're using for field name, but I'll put content in the example.

<description><![CDATA[&nbsp;<?php echo @$slidequotesRecords[$i++]['content']; ?>]]></description>

Arrays that come out of getRecords() are numbered. You can see the array structure by adding this line:
showme($slidequotesRecords);

You don't strictly need to define $i first, but it is good form. At the top of the page you could add:
$i=0;

Hope that helps,
Robin
Robin
Programmer
interactivetools.com