Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change class for last two rows in a while loop

I have a while loop that displays result from a MySQL query. I know how to change the output for the last row or an odd row but how can I change the output for the last two results?

For example I have a list of results in a 2x2 matrix with border-bottom: 1px on each result but I would like to display the bottom two without the border?

like image 481
Ben Avatar asked Jun 08 '26 05:06

Ben


1 Answers

If you can use css3, it´s easy (I´ll use a list for the example):

li:nth-last-child(-n+2)

selects the last two li's.

If you want to do it in php, you can count the number of results, add a counter in your loop and add a class to the last two items.

like image 192
jeroen Avatar answered Jun 10 '26 03:06

jeroen