chrishirst gave you some great advice, but for extra credit, let's change the SQL a little bit, so that your page only asks for the one particular record it's going to use, instead of all of them, managing the "current" pointer through a cursor. As you add more and more students to the table, you'll want to put less pressure on the system.
You'll pass the current record ID and the direction ( next/prev ) in the query string. Based on that, you'll use:
Select Top 1 * From MyTable Where rollno < ID or
Select Top 1 * From MyTable Where rollno > ID
That works for Microsoft ( Access/SQL Server ); with Oracle you'd add And RowNum = 1 to the where clause instead of Top 1. I think in MySql it's Limit 1 at the end of the query, but I'm not sure.
|