0

This question is continue from my last question.

I have jQuery Table Pagination using ORACLE database.

The code like this :

$cur_page = $page;
$page -= 1;
$per_page = 14;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;

$query_pag_data = "
SELECT * FROM
(
    SELECT  x.*, ROWNUM as r FROM
    (
        SELECT P.PRODUCTION_STATUS, P.DATE_ADDED, P.FORM_NO, P.QTY_PLAN, ROWNUM, M.MODEL_NO, M.MODEL_NAME
        FROM SEIAPPS_PRODUCTION_STATUS P, SEIAPPS_MODEL M
        WHERE P.MODEL_NO = M.MODEL_NO
        ORDER BY P.DATE_ADDED DESC, P.TIME
    ) x
)
WHERE r >= $start AND r <= $per_page
";

I limit per page is 14 row. The result for first page is OK, no problem. But when I try to open next page, it's not load the data. Whereas I have more 20 row data in table.

Anyone please help.
Thanks.

4

1 回答 1

0

像这样试试

SELECT * FROM
(
    SELECT  x.* FROM
    (
        SELECT p.production_status, p.date_added, p.form_no, p.qty_plan, ROWNUM r, m.model_no, m.model_name
        FROM   seiapps_production_status p, seiapps_model m
        WHERE  p.model_no = m.model_no
        ORDER BY p.date_added DESC, p.TIME
    ) x
)
WHERE r >= $start AND r <= $per_page
;

如果您想获得带有页码和每页行数的结果,请尝试以下过程。

CREATE OR REPLACE PROCEDURE pagination_proc(
          i_page_num IN NUMBER,
          i_lines_per_page IN NUMBER,
          o_result OUT sys_refcursor)
AS
    l_max_row NUMBER(4) := i_page_num * i_lines_per_page;
    l_rec_count NUMBER(4);
BEGIN
     IF i_page_num = 1 THEN

          SELECT count(*)
          INTO   l_rec_count
          FROM   seiapps_production_status p, seiapps_model m
          WHERE  p.model_no = m.model_no;

     END IF;

     IF l_rec_count > 0 OR i_page_num >1 THEN 
          OPEN o_result FOR
          SELECT production_status, date_added, form_no, qty_plan, model_no, model_name
          FROM
          (
              SELECT production_status, date_added, form_no, qty_plan, model_no, model_name, ROWNUM rn
              FROM 
              (
                  SELECT p.production_status, p.date_added, p.form_no, p.qty_plan, m.model_no, m.model_name
                  FROM   seiapps_production_status p, seiapps_model m
                  WHERE  p.model_no = m.model_no
                  )
                  WHERE ROWNUM <= l_max_row
               )
          WHERE rn > l_max_row - i_lines_per_page;
     END IF; 
END; 
于 2013-09-25T09:21:35.370 回答