QUICK QUESTION!

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

Please send me php code that simply inserts a number next to each listing in order... i.e. 1 for first listing, 2 for second listing, 3 for third, and so on.

I cannot use the "record Num" code because when you delete a listing, it's record number deletes with it.

So the sort order will determine what comes first... but the number 1 will always remain next to the first listing.. and so on. [crazy]
John Tedesco

Creative Director



JAM Graphics

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!

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: [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!

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