0

I am querying an sql db that is fairly large. Some queries return several thousand records.

I'm trying to make a 'next page' link that will return the next 100 records in a query so that only 100 display on each page.

I want to declare a $var as the MAX ID of any given query then when the 'Next page' button is clicked, the query will run again where $var = >100

I was thinking of putting a dowhile into:

  echo '<table class="table table-hover table-condensed table-striped">
        <tr><th>MY_ID</th><th>MT_TYPE</th>';
        foreach($result_head as $row_head) {
            foreach($row_head as $col_headers) {
                $col_heads_split = explode(",",$col_headers);
                foreach($col_heads_split as $col_head) {
                    echo '<th>'.$col_head.'</th>';
                        $maxid = SELECTMAX(MY_ID) FROM dbo.mydb
                        do {
                         $nextpage = *= $maxid
                         while $nextpage = >100
                         }
                }
            }
        }
    echo '</tr>';

So essentially running the same query 100 results at a time.

Thanks for your help!

smkings
  • 13
  • 6
  • 1
    This is called *paging*, E.g. [What is the best way to paginate results in SQL Server](http://stackoverflow.com/questions/109232/what-is-the-best-way-to-paginate-results-in-sql-server) – Alex K. Sep 18 '14 at 12:31
  • Try to use pagination. – Roshan Dandgavhal Sep 18 '14 at 12:42
  • If you are using SQL Server 2012, then FETCH , NEXT will help you. Take a look here http://blog.sqlauthority.com/2013/04/14/sql-server-tricks-for-row-offset-and-paging-in-various-versions-of-sql-server/ – AK47 Sep 18 '14 at 12:42

0 Answers0