Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:48:47+00:00 2026-06-03T14:48:47+00:00

I am trying to display 10 records per page by using ROW_NUMBER function of

  • 0

I am trying to display 10 records per page by using ROW_NUMBER function of SQL SERVER 2008.

I think there is something wrong with my query because I only define where to start and where to end displaying records (from 1 to 10), but not the amount of records displayed per page.

As I go to the next page I get no results displayed at all because I don’t know how to add $per_page variable to my SQL query properly.

All I want is be able to display the first 10 product IDs on page 1, and once I click on the “next” button, the next 10 product IDs will be displayed, etc.

This is the code that I have right now:

$per_page = 10;

if(!isset($_GET['page']))
{
    $page = 1;
}
else
{
    $page = $_GET['page'];  
}

if($page<=1)
{
    $start = 0;
}
else
{
    $start = $page * $per_page - $per_page;
}

$tsql = " SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY productID) AS
rownum, productID FROM products) AS products1
WHERE rownum >= $start AND rownum <= $per_page";


$num_rows = sqlsrv_num_rows(sqlsrv_query($conn,$tsql));

$num_pages = ceil($num_rows / $per_page); 

$stmt = sqlsrv_query($conn,$tsql);
while($row = sqlsrv_fetch_array($stmt)){ 

            echo $row['productID']. "<br/>";

}


$prev = $page - 1;
$next = $page + 1;


echo "<hr>";

//prev
if($prev > 0)
{
    echo "<a href='?page=$prev'>prev</a> ";
}

//numbers
$number = 1;
for($number; $number <= $num_pages; $number +=1)
{
    if($page==$number)
    {
        echo " <b>[$number]</b> ";
    }
    else
    {
        echo "<a href='?page=$number'>$number</a> ";
    }
}

//next 

    echo "<a href='?page=$next'>next</a>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:48:49+00:00Added an answer on June 3, 2026 at 2:48 pm

    I’m not familiar with sql server, but it seems to me you just need the end point:

    $tsql = " SELECT *
        FROM (SELECT ROW_NUMBER() OVER(ORDER BY productID) AS
        rownum, productID FROM products) AS products1
        WHERE rownum >= $start AND rownum < ($start + $per_page)";
                                            ^     changed      ^
    

    And if $page is supposed to be an integer, it’s always best to make sure that it is:

    $page = (int) $_GET['page'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display all records from my table CarCollection using the following
I am able to display my records from SQL Server db in a table.
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying to display some files in a web page so the user can
I'm trying to display an svg graph with associated javascript in my application using
I'm trying to list the number of records per hour inserted into a database
I'm trying to display records within my GridView and a few of the cells
I am trying to display records with Images. I carefully named each image (1.png,
I'm trying to create a SQL 2005 query to retrieve and combine records from
I am trying to access userdata I have sent from the server (using coldfusion)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.