Php + mysql determine the record location ID Catid Order
1 1 1
2 1 5
3 2 3
4 1 2
5 2 15
7 1 11
8 1 9
...
152 1 155
153 1 143
I need to calculate the number of records under the current CATID based on an ID.
For example, if the given ID is 7, the corresponding Catid is 1. The SQL statement is:
SELECT * FROM 'news _ list' WHERE 'tid' = 1 order by 'order' asc limit x, 30
Because it is sorted by order, and there are many data.
The problems to be solved are:
For example, if ID = 7 is given, the position of the ID in the obtained result is calculated based on the Catid to which the ID belongs. (7 is 4th Records)
Hope you can help me.
Ps: If the data volume is large, you cannot read all records that meet the conditions before judging.
My answer is as follows:
Set @ I: = 0; SELECT @ I: = @ I + 1 as num, news_list. * FROM 'News _ list' WHERE 'catid' = 1 order by 'order' asc limit 0, 30