This is a discussion on sql query results and scrolling within the PHP Language forums, part of the PHP Programming Forums category; I make a mySQL database query and display the first 10 results. Then the user can click on "next&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I make a mySQL database query and display the first 10 results. Then
the user can click on "next" link to get the next 10 results. How can I do that without issuing the sql query again? Can I keep the results from the first query? Jens Martin Schlatter |
|
|||
|
Jens Martin Schlatter wrote:
> I make a mySQL database query and display the first 10 results. Then > the user can click on "next" link to get the next 10 results. How can > I do that without issuing the sql query again? Can I keep the results > from the first query? Yes, but I think this is a bad idea. Save the results from the first query in a session variable. It is *much* ( _very_ _much_ ) better to get *only* what you need from the database in the first place. First query select ... limit 0, 10 and then, based on the page number the user wants to see select ... limit ($page_number-1)*10, 10 Check out the MySQL manual for SELECT http://www.mysql.com/doc/en/SELECT.html -- --= my mail address only accepts =-- --= Content-Type: text/plain =-- |
|
|||
|
> > I make a mySQL database query and display the first 10 results. Then
> > the user can click on "next" link to get the next 10 results. How can > > I do that without issuing the sql query again? Can I keep the results > > from the first query? > > It is *much* ( _very_ _much_ ) better to get *only* what you need from > the database in the first place. Thank you very much for your good hint. Do you think it is less overhead to do a query for each page? Jens Schlatter |
|
|||
|
Jens Martin Schlatter wrote:
> Do you think it is less overhead to do a query for each page? Really I don't know. If you're already using sessions *and* the table is small (and will not grow) ?????? Anyway, you will always have to do some processing on every page; either selecting from the array stored in a session variable or having the DB do it for you. Which reminds me: DO use a SORT BY in the queries with a LIMIT clause! Never measured the difference between opening (and closing) a file and opening (and closing) a connection to the database -- but I expect the database thing to be faster :-) -- --= my mail address only accepts =-- --= Content-Type: text/plain =-- |
![]() |
| Thread Tools | |
| Display Modes | |
|
|