By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,247 Members | 871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,247 IT Pros & Developers. It's quick & easy.

"next" page howto?

P: n/a
joe
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(etc etc)
....

Then:
<table>
while ($result = mysql_fetch_array($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
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote:
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?


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.php?startnr=20">next 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, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

P: n/a
joe
On Mon, 22 Sep 2003 21:07:25 +0200, Jan Pieter Kunst wrote:
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote:
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?


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.php?startnr=20">next 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.

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

Jul 17 '05 #3

P: n/a
Jan Pieter Kunst wrote:
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote:

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?

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.php?startnr=20">next 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


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

Jul 17 '05 #4

P: n/a

"joe" <wa*****@home.nl> wrote in message
news:pa****************************@home.nl...
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(etc etc)
...

Then:
<table>
while ($result = mysql_fetch_array($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


http://www.devshed.com/Server_Side/P...ing/page1.html
Jul 17 '05 #5

P: n/a
joe
On Mon, 22 Sep 2003 16:28:50 -0500, Jay Moore wrote:

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

<?php

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

$result = mysql_query("SELECT * 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.
Jul 17 '05 #6

P: n/a
joe
On Mon, 22 Sep 2003 14:31:43 -0700, Steve Edwards wrote:

http://www.devshed.com/Server_Side/P...ing/page1.html

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

P: n/a
joe
On Tue, 23 Sep 2003 00:05:10 +0200, joe wrote:
On Mon, 22 Sep 2003 14:31:43 -0700, Steve Edwards wrote:

http://www.devshed.com/Server_Side/P...ing/page1.html

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

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 :)
Jul 17 '05 #8

P: n/a
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote:
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?


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

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.