0

I have the following query in my Rails Controller:

SELECT CODE_VER FROM MASTERTEST WHERE DATE>= DATE_SUB(CURDATE(), INTERVAL 90 DAY) ORDER BY DATE DESC;

This query returns me results from the last 90 days. I display all these results in a table right now.

I want to show only rows from 7 days at a time in some kind of pagination. I have tried will_paginate and kaminari and also paginate_by_sql. But I haven't been successful using any of them so far.

Can someone show me the exact syntax incase of my query?

Pi Horse
  • 2,350
  • 8
  • 30
  • 51
  • What DBM are you using? MySQL, PostgreSQL, Oracle, SQLite? You can do what you want without plugins, by using the `limit` and `offset` parameters to `select`. Some DBMs don't support `offset` but will have a start/end range for `limit`. – the Tin Man Oct 30 '12 at 00:52
  • @theTinMan : I am using MySQL – Pi Horse Oct 30 '12 at 04:42
  • MySQL's `limit` takes two parameters, `SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15`. – the Tin Man Oct 30 '12 at 05:11

1 Answers1

-1

store the result in a variable say @result

In Controller

@result=SELECT CODE_VER FROM MASTERTEST WHERE DATE>= DATE_SUB(CURDATE(), INTERVAL 90 DAY) ORDER BY DATE DESC;

@result.page(params[:page]).per(10)

In View, use

<% paginate %> # to render the value page by page
Narmadha
  • 55
  • 5