Mssql Page Number Query help TOP , NOT IN ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizdom
    New Member
    • Oct 2008
    • 28

    Mssql Page Number Query help TOP , NOT IN ??

    I'm trying to add simple page support, the page is php/mssql based.

    Anyone know why this doesn't work? I found the "NOT IN" command online but I'm not 100% sure about it..... any help is appreciated

    Currently its displaying the same results every time, no matter what "page" i put it on, obviously not the desired results, i'm familiar with the 'LIMIT' command in mysql, but that doesn't work in mssql.....here' s my code i'm trying:

    Code:
    $posts_per_page = 50;
    $page = 2;
    $page_number = ($page * $posts_per_page) - 50;
    
    $result=mssql_query("SELECT TOP $posts_per_page * FROM Message_Board
    
    WHERE $searchby LIKE '%$search2%' AND id NOT IN 
           ( SELECT TOP $page_number * FROM Message_Board WHERE thread_number=0 ORDER BY TStamp DESC )
    
    ORDER BY TStamp DESC");
    Last edited by wizdom; Oct 6 '08, 02:14 AM. Reason: Clarification
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    This is not really a SQL Server issue. It will just fetch the record that you asked. I found this online. As I am not really familiar with PHP, I don't know what that page is talking about with respect to the code part. But the explanation seems to tell me that it's what you are looking for.

    Happy coding.

    -- CK

    Comment

    • wizdom
      New Member
      • Oct 2008
      • 28

      #3
      I ended up not using the "NOT IN" function as I'm not sure if it was working or not.

      i went with TOP and a couple nested select statements, which worked and got the results I was looking for, although I think the code is a little wierd looking it does work.....basica lly I did:

      SELECT * FROM (SELECT TOP $posts_per_page * FROM (SELECT TOP $inner_query_nu m * FROM <tablename> WHERE thread_number=0 ORDER BY TStamp ASC) AS newtable ORDER BY TStamp DESC) newtable ORDER BY newtable.TStamp DESC")

      $posts_per_page = 50;
      $inner_query_nu mber = $total_entries - (($page_number * $posts_per_page ) - $posts_per_page );

      I got my total entries by doing a simple query b4hand:
      $te=mssql_query ("SELECT * FROM <tablename> WHERE thread_number=0 ");
      $total_entries = mssql_num_rows( $te);

      the only thing missing here is the "page_numbe r" which you would abviously get via a $_GET['page_number']; type deal.

      But it works,

      I do appreciate the quick response thank you.

      Comment

      Working...