By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,266 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,266 IT Pros & Developers. It's quick & easy.

Mssql Page Number Query help TOP , NOT IN ??

P: 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");
Oct 6 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
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
Oct 6 '08 #2

P: 28
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.
Oct 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.