Php + mysql determine record location-php Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.