The content of this article is about how to sort data on html pages? (Attached is the code), which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
I used this little trick when ranking results a few days ago. You can implement data sorting function by directly using el expression in html code. This is my first time blogging, so please give me some advice. .
To rank the results, you must first take out the data in positive order:
select * from table where 1 = 1 order by score desc;
Then use <c:foreach>
to traverse the data and add EL expression at the same time Formula to display the ranking:
<c:set var="number" value="1"></c:set> <c:foreach item="${array }" var="data"> <span>名次:</span>${number } <span>成绩:</span>${data.score } <c:set var="number" value="${number+1 }"></c:set> </c:foreach>
The code uses <c:set>
to define and operate the data number
. If it is paging data, you only need to ${number }
can be replaced with ${number (currentPage-1) }
. Where currentPage
is the page number of the current page.
Related recommendations:
How to implement message board style in html? (Code example)
#How to center-align text in HTML? (Code example)
Code for combining html and css to realize mobile web page adaptation
The above is the detailed content of How to sort data on html pages? (with code). For more information, please follow other related articles on the PHP Chinese website!