PHP - MySQL "next" - "previous" link with ordering -
i have table this
id | name | image | ordering ------+-------------+------------+-------------- 1 | name 1 | one.jpg | 5 ------+-------------+------------+-------------- 2 | name 2 | two.jpg | 2 ------+-------------+------------+-------------- 3 | name 3 | thr.jpg | 3 ------+-------------+------------+-------------- 4 | name 4 | for.jpg | 7 ------+-------------+------------+-------------- 5 | name 5 | fiv.jpg | 1 ------+-------------+------------+-------------- 6 | name 6 | six.jpg | 9 ------+-------------+------------+--------------
my requirement show first image in page according ordering. following query works me
select * images order ordering asc limit 0,1 - row id 5 return
next have show 2 links @ bottom "prev" , "next" ( since first page dont need show "prev" )
okey .. pressing on "next" have show next page ( ie according table row id 2 ). in page need show "prev" leads first result. "next" page must leads row id 3
i have tried
select * images id < $local_id order id desc limit 1 select * images id > $local_id order id asc limit 1
but since having ordering wont work...
can 1 please share idea me ? in advance
in mysql limit x, y
range want get, x starting row (0 being first row) , y being number of rows return
to achieve want need use page numbers each page on, use them calculate x value, y 1 want 1 image on each page.
something started:
<?php $page = (isset($_get['page'])) ? $_get['page'] : 1; $startpoint = $page - 1; $query = "select * images order ordering asc limit $startpoint,1"; $rowcount = 0; // replace count of rows/images
then links like
<a href="index.php?page=1">first</a> <a href="index.php?page=<?php echo $page - 1?>">prev</a> <a href="index.php?page=<?php echo $page + 1?>">next</a> <a href="index.php?page=<?php echo $rowcount;?>last</a>
Comments
Post a Comment