473,487 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simple question about Next and Previous

I really need some help with showing pages of results from queries in
say like groups of 20 with next and previous buttons or links. I'm
having a lot of trouble figuring out the logic of such a script. I know
someone has written this script before. Please help.
Jul 17 '05 #1
9 1918
Leroy <le***@thevelvetbox.net> wrote in message
news:Ij8td.149059$V41.97686@attbi_s52...
I really need some help with showing pages of results from queries in
say like groups of 20 with next and previous buttons or links. I'm
having a lot of trouble figuring out the logic of such a script. I know
someone has written this script before. Please help.


I'm sure there's a more elegant way of doing this but here is a simple, easy
way:
1: Setup your table with an autoincrementing integer field (we'll call this
field recID)

2: Have your SQL statement read something like:
"SELECT * FROM tblName LIMIT 20 ORDER BY recID"

3: Your "next" link should have the number of the last record displayed. So
it might look something like:

"<a href="shownextrecords.php?lastdisplayed=20">Next Records</a>

4: When the "next" link is clicked, query the database the same as before
EXCEPT add a "WHERE recID > $lastdisplayed" to your query so that the
records will be the next 20 records in the database. Keep your ORDER BY and
LIMIT statements the same.

You might want to make check each time you do a query and make sure that the
set being displayed isn't the last set to be displayed. If it is, you
obviously don't wan't to display a "next" link on that set.

Like I said, it's real easy and there are probaby much easier and more
elegant ways to do this. But that's just my take on it. Others here might do
it differently.

Good Luck,
Anthony
Jul 17 '05 #2
hello, here is an example from the manual:

SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15
"Leroy" <le***@thevelvetbox.net> wrote in message
news:Ij8td.149059$V41.97686@attbi_s52...
I really need some help with showing pages of results from queries in say
like groups of 20 with next and previous buttons or links. I'm having a lot
of trouble figuring out the logic of such a script. I know someone has
written this script before. Please help.

Jul 17 '05 #3
Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html

--
Tony Marston

http://www.tonymarston.net
"Leroy" <le***@thevelvetbox.net> wrote in message
news:Ij8td.149059$V41.97686@attbi_s52...
I really need some help with showing pages of results from queries in say
like groups of 20 with next and previous buttons or links. I'm having a lot
of trouble figuring out the logic of such a script. I know someone has
written this script before. Please help.

Jul 17 '05 #4
Tony Marston wrote:
Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html

Yes, that is exactly what I'm looking for, thank you very much.
Jul 17 '05 #5
Tony Marston wrote:
Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html

Tony, I went to that site, got the code, tweaked it a little to fit my
site and it works wonderfully. Thanks for the info, that's one headache
you found the asprin for. Now, if I can come up with a PHP script that
automatically generates money, I'll be in business LOL
Jul 17 '05 #6

"Leroy" <le***@thevelvetbox.net> wrote in message
news:5Oqtd.219514$R05.203831@attbi_s53...
Tony Marston wrote:
Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html

Tony, I went to that site, got the code, tweaked it a little to fit my
site and it works wonderfully. Thanks for the info, that's one headache
you found the asprin for. Now, if I can come up with a PHP script that
automatically generates money, I'll be in business LOL


If you find such a script can you give me a copy :)

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #7
I noticed that Message-ID: <cp*******************@news.demon.co.uk> from
Tony Marston contained the following:
Tony, I went to that site, got the code, tweaked it a little to fit my
site and it works wonderfully. Thanks for the info, that's one headache
you found the asprin for. Now, if I can come up with a PHP script that
automatically generates money, I'll be in business LOL


If you find such a script can you give me a copy :)


Give?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:8i********************************@4ax.com...
I noticed that Message-ID: <cp*******************@news.demon.co.uk> from
Tony Marston contained the following:
Tony, I went to that site, got the code, tweaked it a little to fit my
site and it works wonderfully. Thanks for the info, that's one headache
you found the asprin for. Now, if I can come up with a PHP script that
automatically generates money, I'll be in business LOL


If you find such a script can you give me a copy :)


Give?


OK then, lend me a copy?

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #9
Tony Marston wrote:
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:8i********************************@4ax.com...
I noticed that Message-ID: <cp*******************@news.demon.co.uk> from
Tony Marston contained the following:

Tony, I went to that site, got the code, tweaked it a little to fit my
site and it works wonderfully. Thanks for the info, that's one headache
you found the asprin for. Now, if I can come up with a PHP script that
automatically generates money, I'll be in business LOL

If you find such a script can you give me a copy :)


Give?

OK then, lend me a copy?

hey, let's all get a copy and become the PHP upperclass
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2297
by: Alan Clark | last post by:
Dear All I need to do something very simple with Javascript and have been looking all over the web for two days for a suitable script. I'm the kind of person who learns by seeing how it's done....
11
2672
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
4
4699
by: HS-MOON | last post by:
I'm asking you to help me. I'm a beginner of studying c++. I'm trying to make the Singly Linked List(Ordered). Anyway, I've been debugging all day. I can't sort it out!! As you see, I don't...
13
5707
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was...
1
1440
by: VictorT | last post by:
Hi All, I am trying to create a simple Windows form that lists a users' data one user at a time with the usual "Next" & "Previous" buttons. Upon loading the form, I am able to populate all...
24
2811
by: Ian Rastall | last post by:
I do a site where I have a previous and next link at the bottom of every page. It looks like: <p><a href="foo01.html">Previous</a> | <a href="foo03.html">Next</a></p> Seeing as they're always...
6
2664
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
176
8183
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
55
6397
by: copx | last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints within a specified range? It is important that each value within the range has the same probability (uniform...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.