sql query results and scrolling

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&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-26-2003
Jens Martin Schlatter
 
Posts: n/a
Default sql query results and scrolling

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
Reply With Quote
  #2 (permalink)  
Old 11-26-2003
Pedro Graca
 
Posts: n/a
Default Re: sql query results and scrolling

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 =--
Reply With Quote
  #3 (permalink)  
Old 11-26-2003
Jens Martin Schlatter
 
Posts: n/a
Default Re: sql query results and scrolling

> > 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



Reply With Quote
  #4 (permalink)  
Old 11-26-2003
Pedro Graca
 
Posts: n/a
Default Re: sql query results and scrolling

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 =--
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0