Jump to content

Numbering - Changing sort order


arminvit

Recommended Posts

Hello, I'm a PHP beginner, and I have one question that might be very easy for this forum... I have this code that numbers my comments on a blog. It does so going in ascending order [b]1 2 3 4 5 ...[/b] and I would like it to change the numbering to descending order [b]... 5 4 3 2 1[/b].

[code]
<?php $i = 1; ?>
<MTEntries>
...
<?php $i++;?>
</MTEntries>
[/code]

And this, down here, is what renders the numbers:

[code]<?php echo $i; ?>[/code]

Is there a simple tweak to this?

Thanks!

Armin
Link to comment
https://forums.phpfreaks.com/topic/32693-numbering-changing-sort-order/
Share on other sites

Toon,

Thanks for the quick reply... The descend order changes does change the order of the entries but the numbering stays the same. From your example, is there a way to not have to hard-code how many entries there are?

So, instead of [b]$i = 5;[/b] can you make the [b]5[/b] be an automatically growing number depending on the amount of entries so that as new ones come in, the top one changes to [b]6 7 8 9 10 ...[/b] ?
[code] <?php $i = 5; $i > 0; ?>
<MTEntries sort_order="descend">

<div class="number_green">No. <?php echo $i; ?></div>

<$MTEntryBody$>

<div class="quipped_by">POSTED BY <$MTCommentAuthorLink default_name="Anonymous"$ show_email="1" spam_protect="1" regex="1" apply_macros="1"$><MTCommentAuthorIdentity></div><div class="quipped_on"><$MTCommentDate format="%b.%d.%Y"$></div>
<?php $i--;?>
</MTEntries>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.