Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 6th, 2008, 03:11 AM
Newbie
 
Join Date: Oct 2008
Posts: 12
Default 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;
  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
Reply
  #2  
Old October 6th, 2008, 05:19 AM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,512
Default

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

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
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles