Php makes a ranking based on time

Source: Internet
Author: User
Php makes a ranking by time, and php makes a ranking by time. in the figure, the ranking is in reverse chronological order, and the queuing fields need to be in chronological order.

Correct queuing order and serial number are reversed by 5.4.3.2.1


Reply to discussion (solution)


I'm a master of magic!

Isn't order by time enough?

If the data can be written in reverse order by id

select * from table order by id desc;

Isn't order by time enough?
This method is acceptable, but the previous serial number is based on desc, while the queuing behind is based on asc, so it is difficult. The boss is too picky.

Your queue column does not have data

Order by field
Desc or asc

Ascending desc
Asc in descending order

Your queue column does not have data
Well, there is no data. the serial number column is $ key, which is sorted in descending order. Sort columns in ascending order. SQL statements can only be sorted once. So now we are struggling. The initial plan is to add a field, and then write a loop statement to write the ranking to this field. The id is recycled continuously, so that each data entry has the value of the sorting field. However, it does not loop by ID

So what is the basis of your ranking?

So what is the basis of your ranking?
The ranking is based on the ascending time order, while the serial number is based on the descending time order. So there are two conflicts.

Your serial number is generated by the php code during output.
Then your ranking is the total number-serial number

Ranking 1 52 43 34 2 5 1

Your serial number is generated by the php code during output.
Then your ranking is the total number-serial number

Ranking 1 52 43 34 2 5 1

That's right. I just want this effect. How did it come out? I don't understand.

Isn't it difficult to get the total number of records of the query results?
So
Echo 'sequence number '. $ I. 'ranking'. ($ count-$ I );
$ I ++;
No?

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.