In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to query rankings in php mysql". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "php mysql how to query rankings" bar!
Php mysql query ranking method: 1, rank all users through SQL statement; 2, through "SELECT b.uidjinb.rownum FROM (SELECT t.ranking, @ rownum:...)" Statement to query the ranking of a particular user.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How does php mysql query rankings?
PHP+mysql implements ranking and queries the ranking of specified users
The situation is as follows:
Rank the points of all users in the user table [point] and get the specific ranking of a user's points.
1. First, rank all users
$sql = "SELECT t.questions, @ rownum: = @ rownum + 1 AS rownum FROM (SELECT @ rownum: = 0) r, (SELECT uid,point FROM user ORDER BY `point` DESC) AS t"; $sql = "SELECT t.questions, @ rownum: = @ rownum + 1 AS rownum FROM (SELECT @ rownum: = 0) r, (SELECT uid,point FROM user ORDER BY `point` DESC) AS t"
Note: 1. SELECT @ rownum: = 0: an initial value of 0 is assigned to rownum.
2. @ rownum: = @ rownum + 1: for rownum plus 1, the statement starts with 1, and each line is automatically added with 1.
The above code sorts from largest to smallest according to the point in the user table.
2. Get the ranking of a specific user
Principle: treat the data obtained in the previous step as a table, and query the ranking of specific users according to uid
$sql = "SELECT b.uidjie b.rownum FROM (SELECT t.rownum, @ rownum: = @ rownum + 1 AS rownum FROM (SELECT @ rownum: = 0) r, (SELECT uid,point FROM user ORDER BY `point` DESC) AS t) AS b WHERE b.uid = {$uid}"
Query result: {"uid": "300462", "rownum": "10"}
Where rownum is the ranking of the user.
At this point, I believe that everyone on the "php mysql how to query rankings" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.