Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    Sunshine State
    Posts
    80
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Displaying set of records based on url parameters

    I really don't know how to ask this question...I'm an absolute novice to pdo and have zero knowledge of mssql or sql server or whatever it's called

    I do know that I'm not using MySQL and I do know that LIMIT is not going to work, but I do need a way to pull a limited set of records per page (I did get my pagination script working which is fabulous!); I know I need to use TOP and my assumption is that I need to use BETWEEN as well

    this currently displays "Incorrect syntax near the keyword 'BETWEEN'."
    PHP Code:
      public function paginatedResults($table,$display,$orderby) {
          
    $page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
          
    $s = (isset($_GET['s']) ? (int) $_GET['s'] : 0);
          
    $start = (isset($_GET['s']) ? ($page 1) * $display $display);
          
    $getListQuery $this->pdo->query("SELECT TOP ($display) * FROM $table BETWEEN $start AND ($s+$display)");
          echo 
    'Get List Query: '.var_export($getListQuery,true).'<hr />';
          
    $getListResult = array();
          while (
    $fetch $getListQuery->fetch()) {
              
    $getListResult[] = $fetch;
          }
          return array(
    "getListResult"=>$getListResult);
      } 
    this gives me undefined index notices
    PHP Code:
      public function paginatedResults($table,$display,$orderby) {
          
    $page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
          
    $s = (isset($_GET['s']) ? (int) $_GET['s'] : 0);
          
    $start = (isset($_GET['s']) ? ($page 1) * $display $display);
          
    $getListQuery $this->pdo->query("SELECT TOP ($display) * FROM (SELECT row_number() OVER (ORDER BY $orderby) AS rownum FROM $table) AS A WHERE A.rownum BETWEEN $start AND ($s+$display)");
          echo 
    'Get List Query: '.var_export($getListQuery,true).'<hr />';
          
    $getListResult = array();
          while (
    $fetch $getListQuery->fetch()) {
              
    $getListResult[] = $fetch;
          }
          return array(
    "getListResult"=>$getListResult);
      } 
    I like to think I'm in the general ballpark and need just a lil more help in getting the ball over the fence...any help out there?
    Last edited by dnnhater; 03-29-2013 at 04:40 PM.

  • #2
    New Coder
    Join Date
    Jul 2011
    Location
    Sunshine State
    Posts
    80
    Thanks
    18
    Thanked 0 Times in 0 Posts

    It wasn't easy but I finally got it!

    PHP Code:
      public function paginatedResults($table,$display,$orderby) {
          
    $page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
          
    $s = (isset($_GET['s']) ? (int) $_GET['s'] : 0);
          
    $start = (isset($_GET['s']) ? ($page 1) * $display $display);
          
    $getListQuery $this->pdo->query("SELECT TOP ($display) * FROM (SELECT *,row_number() OVER (ORDER BY $orderby) AS num FROM $table) AS A WHERE num BETWEEN $s AND ($start+$display)");
          
    $getListResult $getListQuery->fetch();
          
    $getListResult = array();
          while (
    $fetch $getListQuery->fetch()) {
              
    $getListResult[] = $fetch;
          }
          return array(
    "getListResult"=>$getListResult);
      } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •