Connecting Tech Pros Worldwide Help | Site Map

Mssql Page Number Query help TOP , NOT IN ??

  #1  
Old October 6th, 2008, 03:11 AM
Newbie
 
Join Date: Oct 2008
Posts: 28
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:

Expand|Select|Wrap|Line Numbers
  1. $posts_per_page = 50;
  2. $page = 2;
  3. $page_number = ($page * $posts_per_page) - 50;
  4.  
  5. $result=mssql_query("SELECT TOP $posts_per_page * FROM Message_Board
  6.  
  7. WHERE $searchby LIKE '%$search2%' AND id NOT IN 
  8.        ( SELECT TOP $page_number * FROM Message_Board WHERE thread_number=0 ORDER BY TStamp DESC )
  9.  
  10. ORDER BY TStamp DESC");

Last edited by wizdom; October 6th, 2008 at 03:14 AM. Reason: Clarification
  #2  
Old October 6th, 2008, 05:19 AM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,915
Provided Answers: 1

re: Mssql Page Number Query help TOP , NOT IN ??


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
  #3  
Old October 8th, 2008, 03:16 AM
Newbie
 
Join Date: Oct 2008
Posts: 28

re: Mssql Page Number Query help TOP , NOT IN ??


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.....basically I did:

SELECT * FROM (SELECT TOP $posts_per_page * FROM (SELECT TOP $inner_query_num * 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_number = $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_number" which you would abviously get via a $_GET['page_number']; type deal.

But it works,

I do appreciate the quick response thank you.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 Logon Issues Lee T. Hawkins answers 3 May 31st, 2007 07:35 AM