How To Reverse The Order Of An Ordered List

by Sheldon Nesdale on 12 April 2010

A client of mine has a huge list of testimonials (more than 50), and rather than counting down the list, it was appropriate to number them backwards so the latest testimonial (in this case, #51) is at the top of the list and numbered #51 rather than #1 (which wouldn’t make much sense).

The End Result: Reversed Order for the Ordered List

End result: Reversed Order for the Ordered List

End Result: Reversed Order for the Ordered List

Here’s what the html code looks like:

<li value="51">Andrew Martin</li>
<li value="50">Carlene Sykes</li>
<li value="49">Lee Clifford</li>
<li value="48">Debrah Breedt</li>
<li value="47">Gina Sterling</li>

Because this testimonial page uses PHP I was able to do this dynamically in the code in 3 steps:

1. Set the start value by counting the total number of testimonials:

$result = mysql_query("SELECT * FROM testimonials");
$testimonial_number = mysql_num_rows($result);

2. Then set the li value with this variable

<li value="$testimonial_number">$student_name</li>

3. Finally, subtract 1 from the counter

$testimonial_number--;

Clever huh?

I made this change because it makes the website just a little bit easier to use and a little more intuitive, and because I care.

Do you want a website developer who cares just as much as you do about your business?

You’ve found him.

Hire me.

Call (07) 575 8799 or email me.

Cheers,

Sheldon.

Welcome Back! What do you think about this article? Write your reaction in the comments below. Thanks for visiting!

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Comment

Previous post:

Next post: