Forum Moderators: coopster

Message Too Old, No Replies

Need help related to pagination like script

help on creating to print next and previous option

         

neo2sxn

11:16 am on Jan 7, 2015 (gmt 0)

10+ Year Member



Hi all,

I just want to create a script that can echo "next" and "previous" or both based on total number of content.

I have parameter in url like :
mysite.com/start=8 (page 1)
mysite.com/start=16 (page 2)
mysite.com/start=24 (page 3) and so on.....

what i want is fetch total number of content from database and print "next" and previous, for example :

If start=8 or start='' then echo next but only if contents are more then 8, If start=16 then echo "next" and "previous", AND If start=24 then echo only "previous".

If possible, Please help me with example code...

Your help will be very thankful...

Demaestro

4:34 pm on Jan 7, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rather than start=8, 16, 24... think in terms of page.

start=1, 2, 3

Then when the page loads calculate how many pages there are...

When you are drawing the previous and next links wrap them in if statements

if ($_GET['start'] > 1) {
<a href="example.com/start=$_GET['start'] - 1 ">Prev</a>
} else {
Prev
}

if ($_GET['start']< $count_of_pages) {
<a href="example.com/start=$_GET['start'] + 1">Next</a>
} else {
Next
}

neo2sxn

4:48 pm on Jan 7, 2015 (gmt 0)

10+ Year Member



Thanks for reply,

You are right, but i have implemented that mathod on several pages so not able to change then...

Any guess on my current requirement ?

neo2sxn

4:49 pm on Jan 7, 2015 (gmt 0)

10+ Year Member



Full problem is here :


I just want to create a script that can echo "next" and "previous" or both based on total number of content.

I have parameter in url like :
mysite.com/index.php?start=8 (page 1)
mysite.com/index.php?start=16 (page 2)
mysite.com/index.php?start=24 (page 3) and so on.....

what i want is fetch total number of content from database and print "next" and previous, for example :

if total no of rows in database are : 32
Item showing per page : 8
getting value "start" from url using $_GET['start'].

If start=0 or start='empty' then echo "next" but only if contents are more then 8, If start=16 then echo "next" and "previous" both, AND If start=24 then echo "next" and "previous" and if start=32 then only echo "Previous".

If possible, Please help me with example code...