Welcome Guest, Not a member yet? Register   Sign In
Viewing one record at a time
#1

[eluser]sore eyes[/eluser]
Hi, I want to be able to cycle though the records in a table one at a time, using buttons for finding first record, next record etc. The pagination class seems only useful for viewing sets of records. So could anyone give me a hint of a trail I should take? Your help would be much appreciated.
#2

[eluser]davidbehler[/eluser]
If you are using MySQL you can use LIMIT.

Code:
SELECT * FROM table LIMIT 0,1;
This would give you the first record.

Code:
SELECT * FROM table LIMIT 17,1;
This would give you the 18th record.

Code:
SELECT * FROM table LIMIT 5,5;
This would give you record 6,7,8,9 and 10.

You could create a function in your controller that has the number of the current record as the only parameter. Let's say you call your parameter $page and pass it to you model. Then you could do this:
Code:
$record = $page -1;
$query = "SELECT * FROM TABLE LIMIT $record, 1;";
I substract 1 from $page because usually you start counting at 1 for the first record but MySQL (as most programming languages) starts 0.

Hope that helps
#3

[eluser]sore eyes[/eluser]
hi waldmeister, many thanks. That's just what I was looking for. Have a great new year.
#4

[eluser]davidbehler[/eluser]
Glad I could help Smile

Great new year!




Theme © iAndrew 2016 - Forum software by © MyBB