title: DB2 SQL Pagination with a variable BETWEEN
body: <p>So, I have to do a pagination for a site database using DB2, showing 10 results per page. However, when I use <code>FETCH FIRST 10 ROWS ONLY</code>, all the pages show the same 10 first results. I searched and figured I had to use <code>BETWEEN 0 AND 9</code> with ranging variables, but no matter what I do I can't seem to get the SQL code right. I always get the error message <code>odbc_fetch_row(): supplied argument is not a valid ODBC result resource</code>. </p>
  
  <p>I created variables for the offset:</p>
  
  <pre><code>//offset for the query
  $limit = 10;
  $offset = ($currentpage - 1)  * $limit;
  $start = $offset + 1;
  $end = min(($offset + $limit), $total);
  $offsetend = $end - 1;
  </code></pre>
  
  <p>And got the info from the DB:</p>
  
  <pre><code>$busca="";
      if(isset($_GET['palavra']))
      {
          $busca=($_GET['palavra']);
      }
      $SQL1 = "SELECT PALAVRA.CODPAL, PALAVRA.NMPAL, PALAVRA.NMLIBTRANS 
      FROM (SELECT ROW_NUMBER() OVER (ORDER BY PALAVRA.NMPAL ASC) AS ROWNUM
      FROM MAXADM.PALAVRA WHERE PALAVRA.NMPAL LIKE '$busca%') AS P 
      WHERE P.ROWNUM BETWEEN $offset AND $offsetend";
  
      $rs1=getInfo($SQL1);
      while(odbc_fetch_row($rs1))
      {
      $cod_palavra = odbc_result($rs1,"CODPAL");
      $palavra = odbc_result($rs1,"NMPAL");
      $librastrans = odbc_result($rs1,"NMLIBTRANS");
      }
  </code></pre>
  
  <p>What am I doing wrong? Thank you so much!</p>