开发者

What would i need to do display urls in order the way they are displayed on SO?

I'm really unsu开发者_StackOverflow社区re of how ordered results are displayed on a page like stack overflow questions. I know how to get the data from the DB but do i use a for each loop to display the data. And how can i paginate?

I know all about display logic on the databse end. What i mean is that i have the data ready but i do not know how to put in on the page to be displayed correctly.

Thanx


You need to use

  • ORDER BY for sorting your results
  • LIMIT for pagination

GET parameters in your requests should determine the values applied to those statements.


To order results, you should add a "ORDER BY" clause to your SQL statement. Specifically, for StackOverflow default view, it shows questions by date (with the most recent most). This implies that each question has the datetime which it is created tagged to it.

As for pagination, here's a general outline of the code

  1. Find total number of records
  2. Decide how many records per page
  3. Find out how many pages (record per page/page)
  4. Check what's the current page number
  5. Calculate the parameters to add to the LIMIT clause in the SQL statement. The start record should be current page * records per page.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜