Pagination is necessary?
Is pagination important? What happens if you have like 200 entries. Will it slow down the website for people using it?
Sorry if this sounds like an easy question, just wondering, new to the game.
Thanks
Update:
开发者_如何学GoAfter reading answers. I think its important that I use them. So how can i do search pages using limit. Not looking for a fancy solution..
It's more efficient, quick, and server-friendly to break the results up into multiple pages.
For one, most users aren't going to look beyond the first X results regardless of how many there are on one page, so there would be a lot of results unused that were retrieved, processed, and sent to the client which is wasted bandwidth and CPU time. In fact, by paginating you increase the chance that they will continue on beyond where they would have stopped if it were all on one page.
Two, if this were just text data it would be pretty quick even for a large amount of data, but if you throw in pictures and stuff that have to be displayed for each result, such as in a catalog, then things really start slowing down the more results which are returned.
Pagination via LIMIT in SQL is done by using a Limit range. When a single argument is given for LIMIT in an SQL query, then it will return up to that amount of results, so SELECT * FROM table LIMIT 5
will return at most 5 results. When two arguments are given, it skips results until it reaches the first argument, then returns up to the next number of results. So, SELECT * FROM table LIMIT 40,10
will return at most 10 records starting from the 41st result.
So, what you need is some way to tell the server what page or result the client is wanting, usually this is done by the pagination links with something like: http://www.domain.com/search.php?p=4
or http://www.domain.com/search.php?r=40
, which you then use that value via $_GET to determine what the limits in the SQL query would be. Something like (using passing the page number via get in this case):
<?php
$sql = "SELECT * FROM `table`"; //Set up initial query string
$max_per_page = 20; //Max results per page, can be drawn from elsewhere/configuration file or something or declared directly
if(isset($_GET['p'])) //Check to see if $_GET['p'] is set
{
$current_limit = abs((int)$_GET['p'] - 1) * $max_per_page; //Current limit = max * (current page - 1) other wise, page 2 would have a starting point of 40 instead of 20 like it should. When passing the result number to start on, you'd just use that instead
}
else
{
$current_limit = 0;
}
$sql .= ' LIMIT ' . $current_limit . ', ' . $max_per_page; //Construct LIMIT on end of query string
$result = mysql_fetch_assoc(mysql_query($sql));
?>
Oh, and to figure out the total results, you can do a SELECT COUNT(*) FROM table WHERE etc. etc.
type statement to start with so you know the total results, which can be used to determine how many pages are necessary since you know the max results per page.
Good pagination will help you both to reduce the weight of the page you serve to the client and the query charge on the database. (because you only need to load 10 or 20 items instead of thousand).
And of course, User Experience is very important too. No one want to scroll for days to find something on a webpage.
I think there is a bigger psychological barrier than technological. Most hardware is capable of paginating large quantities of text very quickly. However, people are unlikely to read a very ling article all the way through.
It is generally good practice to break large amounts of text into smaller pieces for the user's convenience - and offer full text as a download.
Also, the length of the line and spacing is important to capture the audience. I would recommend 1.5em line spacing and about 15 words per line max.
Unlike with printed media - people are not likely to get to the end - and to find out who-dunnit, they will just bail if they don't enjoy a couple of paragraphs. Just imagine the reader with their finger poised on the left button, and another on the scroll wheel - rather like you probably are doing right now - just itching to get off this page and read something else.
Pagination is necessary? Depends. Every time I wrote any page that list entities from the database, I put some pagination (on demand) on them.
But if I am adding a, lets say, new client
, that may have a State
? In that case, the select box that displays all the states would not be paginated. Because its easy for the user to read, and it will normally not load tons of data.
But for more complex and bigger queries, you always must set a limit and load data from your database on demand. All software grows up. If you don't paginate, someday you will have some headaches.
It gives a better sense of completion and if you use it right, a better way to show what you want your users to see (best deals, cheapest rates, etc) quickly. In my opinion, it would keep their attentions span better too.
精彩评论