It's not super elegant but you could use a straight for loop and just do some simple calculations to determine when you have done the third loop. Since I am not doing anything like yours, and don't have the full code there is no way for me to test. However, I believe I have walked the logic in my head a couple of times. Please let me know if this works...
<?php
// Get the total number of ads available in the incoming query
$adsAvailable = count($ads);
$adCount = 0;
for ( $i = 0; $i <= ($adsAvailable - 1); $i++ ) {
// Get the number of ads available - we substract the loop counter from the total
// ads available. Remembering that arrays are 0 indexed so we subtract 1 from
// the overall count
if ($i === 0) { ?>
<div class="item active">
<?php
}
$adsLeft = ($adsAvailable - 1) - $i;
?>
<a class="adshref" href="//<?php echo $ads[$i]['Ad']['link']?>"><?php echo $$ads[$i]['Ad']['title']?></a><br>
<span class="adslink"><?php echo $ads[$i]['Ad']['link']?></span><br>
<span class="adsbody"><?php echo $ads[$i]['Ad']['body']?></span><br>
<?php
if (($adCount % 2) == 0) {
// This is a final in a triple ad so we need to close out the current div
?>
</div>
<?php
if ($adsLeft > 0) {
// Reset the ad counter
$adCount = 0;
// Open the next item
?>
<div class="item">
<?php }
}
}
?>
Thanks,
Vinnie
On Tuesday, January 1, 2013 3:32:41 PM UTC-5, SvenP wrote:
Everything from the source is there, like I said, everything works as expected.If I remove the if($indexValue == 0) exception then I first get a blank slide and then the other Ads in slides.Now I want to change the code to display 3 Ads in each slide.Op 1-jan.-2013, om 21:05 heeft lowpass <zijn.d...@gmail.com> het volgende geschreven:But are you only trusting what the browser displays? Are the other
elements there in the source? What do you see when you disable
javascript? What about when you remove the "active" class?
On Tue, Jan 1, 2013 at 2:10 PM, Sven Pype <sv...@dskbvba.be> wrote:Hi,
The whole thing works perfectly and shows 1 ad for each slide.
My goal is to have 3 ads from the db in 1 slide...
I can't find a solution for it whit a foreach loop...
Thanks anyway.
Sven
On Tue, Jan 1, 2013 at 8:05 PM, lowpass <zijn.d...@gmail.com> wrote:
Is it possible that the other divs are being generated, but are
hidden? What do the item & active class rules look like? Or maybe some
JS is keeping the others from displaying? Try disabling the carousel
activation code.
On Sun, Dec 30, 2012 at 1:55 PM, SvenP <sv...@dskbvba.be> wrote:Yes,
Each ad relates to a sponsor... works perfect.
array(
(int) 0 => array(
'Ad' => array(
'id' => '2',
'sponsor_id' => '0',
'title' => '...',
'body' => '...',
'link' => 'www....com'
),
'Sponsor' => array(
'id' => '8',
'name' => ...,
'contact_first_name' => ...,
'contact_name' => ...,
'contact_tel' => ...,
'contact_email' => ...
)
),
On Sunday, December 30, 2012 7:20:54 PM UTC+1, cricket wrote:
die(debug($ads));
Are you certain of the array structure?
On Sat, Dec 29, 2012 at 5:39 PM, SvenP <sv...@dskbvba.be> wrote:Hi,
I'm looking for a way to show multiple 'Ads' / slide with a foreach
loop
from the db. ( each client has ads tied to them.)
My code now works great but only shows one ad / slide.
Thanks for your time!
Sven
Code:
___________
<div class="carousel-inner">
<?php foreach ($ads as $indexValue => $ad):
if($indexValue == 0){?>
<div class="item active">
<a class="adshref" href="//<?php echo $ad['Ad']['link']?>"><?php echo
$ad['Ad']['title']?></a><br>
<span class="adslink"><?php echo $ad['Ad']['link']?></span><br>
<span class="adsbody"><?php echo
$ad['Ad']['body']?></span><br></div><?php
} else { ?>
<div class="item">
<a class="adshref" href="//<?php echo $ad['Ad']['link']?>"><?php echo
$ad['Ad']['title']?></a><br>
<span class="adslink"><?php echo $ad['Ad']['link']?></span><br>
<span class="adsbody"><?php echo $ad['Ad']['body']?></span><br></div>
<?php } endforeach; ?> </div>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google
Groups
"CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to
cake-php+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en .
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google
Groups
"CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to
cake-php+u...@googlegroups.com .
Visit this group at http://groups.google.com/group/cake-php?hl=en .
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to
cake-php+u...@googlegroups.com .
Visit this group at http://groups.google.com/group/cake-php?hl=en .
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to
cake-php+u...@googlegroups.com .
Visit this group at http://groups.google.com/group/cake-php?hl=en .
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
To unsubscribe from this group, send email to cake-php+u...@googlegroups.com .
Visit this group at http://groups.google.com/group/cake-php?hl=en .
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
No comments:
Post a Comment