QUICK QUESTION!

8 posts by 2 authors in: Forums > CMS Builder
Last Post: August 29, 2009   (RSS)

Re: [jtedescojam] QUICK QUESTION!

By Chris - August 29, 2009

Hi jtedescojam,

Find the foreach statement in your page that is looping over your records:

<?php foreach ($productRecords as $record): ?>
...
<?php endforeach; ?>


Add the lines in bold around the foreach statement and you'll have your counter!

<?php $counter = 0; ?>
<?php foreach ($productRecords as $record): ?>
<?php $counter++; ?>
<?php echo $counter; ?>
...
<?php endforeach; ?>


Hope this helps! Please let us know if you have any questions or comments.
All the best,
Chris

Re: [chris] QUICK QUESTION!

By jtedescojam - August 29, 2009

perfect. One more quick favor though... I need to run 2 sets of counters simultaneously that match. But when I insert this code into 2 seperate places, it continues the count, it doesn't start a whole new counter.

So how would I put in the code so I have a list of numbers 1 through 10 using the counter you gave me.. along side another list of numbers 1 through 10, using the same code?
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] QUICK QUESTION!

By Chris - August 29, 2009

Hi,

Did you forget to add the <?php $counter = 0; ?> code before the second time you start counting?

If that's not the problem, please attach the PHP source code of the page your working here and we'll have a look.
All the best,
Chris

Re: [chris] QUICK QUESTION!

By jtedescojam - August 29, 2009 - edited: August 29, 2009

Yes I added that to the second counter.. but when I do that.. the first counter doesn't count... just displays all ones.. and the second counter just displays all twos.

Keep in mind also... the reason for this counter is specifically in order to call up the javascript collapse effect in the head. seen here: http://www.recamerica.com/REC/featuredListings2.php

<?php $counter = 0; ?>
<?php foreach ($featured_listingsRecords as $record): ?>
<div id="listing" class="clienteditor">
<div id="listing-town" ><a href="javascript:animatedcollapse.toggle('listing-body-<?php $counter++; ?><?php echo $counter; ?>')">
<div id="city-state"><?php echo $record['title'] ?></div>
<div id="price"><?php echo $record['price'] ?></div>
</a></div>

<div id="listing-body-<?php $counter = 0; ?><?php $counter++; ?><?php echo $counter; ?>">
<?php foreach ($record['photo'] as $upload): ?>
<div id="listing-photo"><a href="<?php echo $record['website_link'] ?>" target="_blank"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' border="0"/><br/>
<?php endforeach ?></a></div>
</div>
</div>
<?php endforeach; ?>

And the result must look like this:
<a href="javascript:animatedcollapse.toggle('listing-body-1')">
<div id="listing-body-1"></div>

<a href="javascript:animatedcollapse.toggle('listing-body-2')">
<div id="listing-body-2"></div>

etc...

Also.. view this URL to see how this should work in the end.. except this one works because I RIGGED the numbers manually.. (no good because I need to be able to mix up the listings often using the sort order). http://www.recamerica.com/REC/featuredListings.php
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] QUICK QUESTION!

By Chris - August 29, 2009

Hi,

Ah-ha! You want one counter, but you want to display its value twice?

If I understand what you want correctly, you'll need to replace this line:

<div id="listing-body-<?php $counter = 0; ?><?php $counter++; ?><?php echo $counter; ?>">

with this:

<div id="listing-body-<?php echo $counter; ?>">

Please let us know if this solves your problem! :)
All the best,
Chris

Re: [chris] QUICK QUESTION!

By jtedescojam - August 29, 2009

AHHHH.. that's it! here's the finished product...

http://www.realtyexecutivesnj.com
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] QUICK QUESTION!

By Chris - August 29, 2009

Wow!! That's gorgeous!

Nicely done! :D
All the best,
Chris