"next" page howto?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe

    "next" page howto?

    Can anyone help me out by either telling me how to get to the result i
    need or by pointing me to some documentation about the following question:

    A certain query to a database give me eg 100 results:

    $query = "select id, name, addr1, addr2, city from mytable where id="
    ..$id;
    $connection = mysql_connect(e tc etc)
    ....

    Then:
    <table>
    while ($result = mysql_fetch_arr ay($connection) ){
    <tr>
    <td>echo $result['name]; </td>
    <td>echo $result['addr1']; </td>
    </tr>
    }
    </table>

    This all works well, but will give me all eg 100 results in one webpage.
    What i want however is max 10 results per page, and then a link in the
    bottom of a page with "next" reloading that page but then displaying
    result 11-20 etc etc.
    Now i've been puzzling about that the last couple of days but i just can't
    get that to work. Anyone any suggestions / links / idea?

    tia.
    Joe
  • Jan Pieter Kunst

    #2
    Re: &quot;next&quot ; page howto?

    In article <pan.2003.09.22 .18.48.06.36135 6@home.nl>,
    "joe" <wannebe@home.n l> wrote:
    [color=blue]
    > This all works well, but will give me all eg 100 results in one webpage.
    > What i want however is max 10 results per page, and then a link in the
    > bottom of a page with "next" reloading that page but then displaying
    > result 11-20 etc etc.
    > Now i've been puzzling about that the last couple of days but i just can't
    > get that to work. Anyone any suggestions / links / idea?[/color]

    for first 10 results:

    SELECT ... FROM ... WHERE ... LIMIT 0,10

    for results 11-20:

    SELECT ... FROM ... WHERE ... LIMIT 10,10

    for results 21-30:

    SELECT ... FROM ... WHERE ... LIMIT 20,10

    etcetera. You can put the 'starting number' (first number of the LIMIT,
    the number of rows to be skipped) somewhere in your 'next page' URL to
    build your query, for example, for the "LIMIT 20,10" query:

    <a href="script.ph p?startnr=20">n ext page</a>

    the value for 'previous page' links would be $_GET['startnr'] - 10, for
    'next page' links it would be $_GET['startnr'] + 10. The value '10' for
    'number of results per page' could be a constant defined somewhere. You
    get the idea.

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • joe

      #3
      Re: &quot;next&quot ; page howto?

      On Mon, 22 Sep 2003 21:07:25 +0200, Jan Pieter Kunst wrote:
      [color=blue]
      > In article <pan.2003.09.22 .18.48.06.36135 6@home.nl>,
      > "joe" <wannebe@home.n l> wrote:
      >[color=green]
      >> This all works well, but will give me all eg 100 results in one webpage.
      >> What i want however is max 10 results per page, and then a link in the
      >> bottom of a page with "next" reloading that page but then displaying
      >> result 11-20 etc etc.
      >> Now i've been puzzling about that the last couple of days but i just can't
      >> get that to work. Anyone any suggestions / links / idea?[/color]
      >
      > for first 10 results:
      >
      > SELECT ... FROM ... WHERE ... LIMIT 0,10
      >
      > for results 11-20:
      >
      > SELECT ... FROM ... WHERE ... LIMIT 10,10
      >
      > for results 21-30:
      >
      > SELECT ... FROM ... WHERE ... LIMIT 20,10
      >
      > etcetera. You can put the 'starting number' (first number of the LIMIT,
      > the number of rows to be skipped) somewhere in your 'next page' URL to
      > build your query, for example, for the "LIMIT 20,10" query:
      >
      > <a href="script.ph p?startnr=20">n ext page</a>
      >
      > the value for 'previous page' links would be $_GET['startnr'] - 10, for
      > 'next page' links it would be $_GET['startnr'] + 10. The value '10' for
      > 'number of results per page' could be a constant defined somewhere. You
      > get the idea.
      >[/color]


      Yep thanx got the idea, and and even works:) However i haven't been totally
      clear in the first post: I posted a part of the problem I have and I used
      MySql as one of them. But i have to make that query on both a mysql server
      and on a sybase server. And sybase don't know the "LIMIT" option, and from
      what i've read in me search for a solution, not an equivalent for that
      either which i can use from within php. So something like:
      $query = "set rowcount 5 select name, addr from sometable where id=" .$id
      doesn't work. You know of any options for that as well?

      again tia,
      Joe

      Comment

      • Jay Moore

        #4
        Re: &quot;next&quot ; page howto?

        Jan Pieter Kunst wrote:[color=blue]
        > In article <pan.2003.09.22 .18.48.06.36135 6@home.nl>,
        > "joe" <wannebe@home.n l> wrote:
        >
        >[color=green]
        >>This all works well, but will give me all eg 100 results in one webpage.
        >>What i want however is max 10 results per page, and then a link in the
        >>bottom of a page with "next" reloading that page but then displaying
        >>result 11-20 etc etc.
        >>Now i've been puzzling about that the last couple of days but i just can't
        >>get that to work. Anyone any suggestions / links / idea?[/color]
        >
        >
        > for first 10 results:
        >
        > SELECT ... FROM ... WHERE ... LIMIT 0,10
        >
        > for results 11-20:
        >
        > SELECT ... FROM ... WHERE ... LIMIT 10,10
        >
        > for results 21-30:
        >
        > SELECT ... FROM ... WHERE ... LIMIT 20,10
        >
        > etcetera. You can put the 'starting number' (first number of the LIMIT,
        > the number of rows to be skipped) somewhere in your 'next page' URL to
        > build your query, for example, for the "LIMIT 20,10" query:
        >
        > <a href="script.ph p?startnr=20">n ext page</a>
        >
        > the value for 'previous page' links would be $_GET['startnr'] - 10, for
        > 'next page' links it would be $_GET['startnr'] + 10. The value '10' for
        > 'number of results per page' could be a constant defined somewhere. You
        > get the idea.
        >
        > JP
        >[/color]

        I've had kind of the same question. I know how to do the limiting and
        all, but my question lies in the count() function.

        I'm assuming to find out how many total pages there would be, I'd have
        to count the total number of rows returned and divide by how many I plan
        on having displayed per page. How do I do that count?

        I'm pretty sure I'll have to do two queries. One to get the total
        number of rows returned, and another that includes the LIMIT. I'd be
        very much obliged if someone could post a quick code excerpt on how to
        do that.

        TIA,
        Jay

        Comment

        • Steve Edwards

          #5
          Re: &quot;next&quot ; page howto?


          "joe" <wannebe@home.n l> wrote in message
          news:pan.2003.0 9.22.18.48.06.3 61356@home.nl.. .[color=blue]
          > Can anyone help me out by either telling me how to get to the result i
          > need or by pointing me to some documentation about the following question:
          >
          > A certain query to a database give me eg 100 results:
          >
          > $query = "select id, name, addr1, addr2, city from mytable where id="
          > .$id;
          > $connection = mysql_connect(e tc etc)
          > ...
          >
          > Then:
          > <table>
          > while ($result = mysql_fetch_arr ay($connection) ){
          > <tr>
          > <td>echo $result['name]; </td>
          > <td>echo $result['addr1']; </td>
          > </tr>
          > }
          > </table>
          >
          > This all works well, but will give me all eg 100 results in one webpage.
          > What i want however is max 10 results per page, and then a link in the
          > bottom of a page with "next" reloading that page but then displaying
          > result 11-20 etc etc.
          > Now i've been puzzling about that the last couple of days but i just can't
          > get that to work. Anyone any suggestions / links / idea?
          >
          > tia.
          > Joe[/color]

          Founded in 1997, DEVShed is the perfect place for web developers to learn, share their work, and build upon the ideas of others.



          Comment

          • joe

            #6
            Re: &quot;next&quot ; page howto?

            On Mon, 22 Sep 2003 16:28:50 -0500, Jay Moore wrote:

            [color=blue]
            > I've had kind of the same question. I know how to do the limiting and
            > all, but my question lies in the count() function.
            >
            > I'm assuming to find out how many total pages there would be, I'd have
            > to count the total number of rows returned and divide by how many I plan
            > on having displayed per page. How do I do that count?
            >
            > I'm pretty sure I'll have to do two queries. One to get the total
            > number of rows returned, and another that includes the LIMIT. I'd be
            > very much obliged if someone could post a quick code excerpt on how to
            > do that.
            >
            > TIA,
            > Jay[/color]


            <?php

            $link = mysql_connect(" localhost", "someuser", "somepass") ;
            mysql_select_db ("db", $link);

            $result = mysql_query("SE LECT * FROM table1", $link);
            $num_rows = mysql_num_rows( $result);

            $max_per_page = 10;

            $no_of_pages = $num_rows / $max_per_page;

            ?>

            or s/mysql/sybase in case you're using sybase

            hth.

            Comment

            • joe

              #7
              Re: &quot;next&quot ; page howto?

              On Mon, 22 Sep 2003 14:31:43 -0700, Steve Edwards wrote:
              [color=blue]
              >
              > http://www.devshed.com/Server_Side/P...ing/page1.html[/color]


              Yep nice tutorial but that's mysql and based on
              limiting the query with "LIMIT" which is not a sybase statement..

              Comment

              • joe

                #8
                Re: &quot;next&quot ; page howto?

                On Tue, 23 Sep 2003 00:05:10 +0200, joe wrote:
                [color=blue]
                > On Mon, 22 Sep 2003 14:31:43 -0700, Steve Edwards wrote:
                >[color=green]
                >>
                >> http://www.devshed.com/Server_Side/P...ing/page1.html[/color]
                >
                >
                > Yep nice tutorial but that's mysql and based on
                > limiting the query with "LIMIT" which is not a sybase statement..[/color]


                Forget that previous post you answered to a thread where i dind't mention
                (yet) that i needed that "limiting" on a sybase server as well. Sry :)

                Comment

                • Jan Pieter Kunst

                  #9
                  Re: &quot;next&quot ; page howto?

                  In article <pan.2003.09.22 .20.56.45.50564 8@home.nl>,
                  "joe" <wannebe@home.n l> wrote:
                  [color=blue]
                  > But i have to make that query on both a mysql server
                  > and on a sybase server. And sybase don't know the "LIMIT" option, and from
                  > what i've read in me search for a solution, not an equivalent for that
                  > either which i can use from within php. So something like:
                  > $query = "set rowcount 5 select name, addr from sometable where id=" .$id
                  > doesn't work. You know of any options for that as well?[/color]

                  No, sorry, I never used Sybase so I can't help you with that.

                  JP

                  --
                  Sorry, <devnull@cauce. org> is een "spam trap".
                  E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

                  Comment

                  Working...