467,134 Members | 917 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

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:

Expand|Select|Wrap|Line Numbers
  1. $posts_per_page = 50;
  2. $page = 2;
  3. $page_number = ($page * $posts_per_page) - 50;
  5. $result=mssql_query("SELECT TOP $posts_per_page * FROM Message_Board
  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 )
  10. ORDER BY TStamp DESC");
Oct 6 '08 #1
  • viewed: 2372
2 Replies
Expert 2GB
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
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.

Similar topics

9 posts views Thread by Darren | last post: by
14 posts views Thread by Andre | last post: by
14 posts views Thread by Kukurydz | last post: by
4 posts views Thread by kenneth.osenbroch@telenor.com | last post: by
4 posts views Thread by LamSoft | last post: by
3 posts views Thread by sharijl | last post: by
14 posts views Thread by guswebb | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.