开发者

how to show the last entry on first in php? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be 开发者_StackOverflow中文版reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a program that deals with huge amount of data. The process is like this, first I enter the client's name and account number, then it's saved in a db, then I get the record from there and enter his/her electricity consumption for every month in an accounting year. I want to show the last entered data on first, so that I can apply pagination. How can I do that? Thanks for the help!


You can just call your "last data" by querying by your table Autoincrement key (usually Id) ordering by the same key (DESC) and limiting the result to fetch just the first row

Ex:

SELECT * FROM myTable ORDER BY id DESC LIMIT 1


use ORDER BY fieldName DESC clause:

SELECT * FROM mytable ORDER BY id DESC;

this will select records ordered by Id in descending order... you can put any column instead of id. e.g date field if it's more relative to your problem.


Assuming your DB structure is like:

Table: clients

client_id [PK]

name

...

Table: electricity_consumptions

client_id [FK]

quantity

dated

You can have an SQL like:

select * from electricity_consumptions where client_id =1 ORDER BY dated DESC

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜