473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Mssql Page Number Query help TOP , NOT IN ??

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
2 2615
ck9663
2,878 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
wizdom
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

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

Similar topics

9
by: Darren | last post by:
Hi wondering if anyone can help. What i'm trying to do is get a company from a MSSQL database with the COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to reference it to...
14
by: Andre | last post by:
Hello Can anyone help me translate this from access so that it can work in mssql (i need to get next value, but cannot use identity as if row is deleted, another must get new next column number...
14
by: Kukurydz | last post by:
I've got such problem: My database is stored on MSSQL Server. I have to write reports for it in MSAccess. I've got a problem with creating a query which will select records from MSSQL table with...
4
by: kenneth.osenbroch | last post by:
Hi, I have a MSSQL Server communicating with an Oracle database through a MSSQL linked server using a MS ODBC connection. If I query the Oracle database through the Oracle ODBC 32Bit Test, the...
4
by: LamSoft | last post by:
I've got some perfermance issue while fetching data from MSSQL I have a gridview, the datasource is a objectdatasource, and the objectdatasource is pointed to the dataset. The Select Query in...
3
sharijl
by: sharijl | last post by:
I see tutorials all over the web with pagination and MySQl but not much out there (that is updated using PHP 5 without global variables) on doing this using ODBC connection with MSSQL. This is...
14
by: guswebb | last post by:
Hi. I'm a newbie to PHP and am having a few problems as follows... I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to...
3
by: laural4705 | last post by:
Hi, I would like to know if this is possible, I have a sql table that has a paragraph in a varchar field. I can query the database and pull this field in, it renders perfectly, except for the php...
9
by: chromis | last post by:
Hi, I've never coded in ASP before and I'm trying to port a couple of simple PHP files to ASP.NET. The first file addScores.php takes form data and a hash and inserts the data into the db, it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.