1

i have a student record table with rollno as id how can i get the first,previous,next,last records on button click from the database using php

i used $rollno+1 for next record and $rollno-1 for previous record

When a rollnum is missing then it should go for the next or previous record

For example : i have rollnums like this 1,2,3,5,6.....

When my roll num is 3 when i click next it should display the next record that is record with rollno num 5 how can i get this similarly for the previous record

Help me with this

Sal00m
  • 2,938
  • 3
  • 22
  • 33
arnavi
  • 5
  • 1

2 Answers2

0

Unable to post in comments. So posting Here

Can you put something thay you had tried. A piece of code.

arunrc
  • 628
  • 2
  • 14
  • 26
0

USE LIMIT

$rollnext=$roll+1;
$rollprev=$roll-1;

SELECT * FROM `records` order by `rollnum ` limit $rollnext,1
SELECT * FROM `records` order by `rollnum ` limit $rollprev,1

eg: current page:2

next: 3 previous:1

SELECT * FROM `records` order by `rollnum ` limit 3,1
SELECT * FROM `records` order by `rollnum ` limit 1,1

record 1: SELECT * FROM `records` order by `rollnum ` limit 0,1
record 2: SELECT * FROM `records` order by `rollnum ` limit 1,1
record 3: SELECT * FROM `records` order by `rollnum ` limit 2,1
record 4: SELECT * FROM `records` order by `rollnum ` limit 3,1
record 5: SELECT * FROM `records` order by `rollnum ` limit 4,1
record 6: SELECT * FROM `records` order by `rollnum ` limit 5,1

and so on

sumit
  • 15,003
  • 12
  • 69
  • 110