sql query results and scrolling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jens Martin Schlatter

    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
  • Pedro Graca

    #2
    Re: sql query results and scrolling

    Jens Martin Schlatter wrote:[color=blue]
    > 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?[/color]

    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


    --
    --= my mail address only accepts =--
    --= Content-Type: text/plain =--

    Comment

    • Jens Martin Schlatter

      #3
      Re: sql query results and scrolling

      > > I make a mySQL database query and display the first 10 results. Then[color=blue][color=green]
      > > 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?[/color]
      >
      > It is *much* ( _very_ _much_ ) better to get *only* what you need from
      > the database in the first place.[/color]

      Thank you very much for your good hint.
      Do you think it is less overhead to do a query for each page?

      Jens Schlatter



      Comment

      • Pedro Graca

        #4
        Re: sql query results and scrolling

        Jens Martin Schlatter wrote:[color=blue]
        > Do you think it is less overhead to do a query for each page?[/color]

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

        Comment

        Working...