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