<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Paging Data with the SQL Server Driver for PHP</title><link>http://blogs.msdn.com/sqlphp/archive/2009/03/23/paging-data-with-the-sql-server-driver-for-php.aspx</link><description>One of the most common tasks of any web application involves allowing a user to ‘page’ through a large amount of data. In other words, given a large result set, the task is to present the user with a manageable subset and allow him/her to navigate through</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Paging Data with the SQL Server Driver for PHP</title><link>http://blogs.msdn.com/sqlphp/archive/2009/03/23/paging-data-with-the-sql-server-driver-for-php.aspx#9530756</link><pubDate>Fri, 03 Apr 2009 19:21:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9530756</guid><dc:creator>jezjones</dc:creator><description>&lt;p&gt;There are more important assumptions made which were not pointed out;-&lt;/p&gt;
&lt;p&gt;1) The data has a non-unique incrementing key.&lt;/p&gt;
&lt;p&gt;2) You dont want to sort by any useful fields, only by ID. This is not a real-world situation.&lt;/p&gt;
&lt;p&gt;Also how would you page through a complex query that joins several tables? (none of the articles elsewhere on MSDN cover this either... )&lt;/p&gt;
&lt;p&gt;Nice article, but so basic that it can only be useful in the most rudimentary of programming situations.&lt;/p&gt;
</description></item><item><title>re: Paging Data with the SQL Server Driver for PHP</title><link>http://blogs.msdn.com/sqlphp/archive/2009/03/23/paging-data-with-the-sql-server-driver-for-php.aspx#9530919</link><pubDate>Fri, 03 Apr 2009 23:07:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9530919</guid><dc:creator>Brian Swan</dc:creator><description>&lt;p&gt;jezjones-&lt;/p&gt;
&lt;p&gt;Thanks for the feedback. The examples in the post were kept simple to (hopefully) keep the focus on the paging strategy. By tweaking the $tsql that you execute, you can sort by fields other than ID, and you can page through a JOIN.&lt;/p&gt;
&lt;p&gt;For example, this query does not sort by ID (and it works in the posted code with only a change to the $params array):&lt;/p&gt;
&lt;p&gt;$tsql = &amp;quot;WITH Products AS &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (SELECT ROW_NUMBER() OVER(ORDER BY ListPrice) &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AS RowNumber, Name, ListPrice &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM Production.Product&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE Name LIKE '%' + ? + '%' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND ListPrice &amp;gt; 0.0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT * FROM Products&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE RowNumber BETWEEN ? AND ? + 1&amp;quot;;&lt;/p&gt;
&lt;p&gt;And, this JOIN works with the code in the post:&lt;/p&gt;
&lt;p&gt;$tsql = &amp;quot;WITH Products AS &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(SELECT ROW_NUMBER() OVER(ORDER BY OrderQty) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AS RowNumber, OrderQty, Name &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM Sales.SalesOrderDetail AS s&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN Production.Product AS p&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ON s.ProductID = p.ProductID)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT * FROM Products&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE RowNumber BETWEEN ? AND ? + 1&amp;quot;;&lt;/p&gt;
&lt;p&gt;Yes, these are still simple (even contrived) examples. But, I think they demonstrate that the paging strategies posted are viable for the situations you mention. Do you agree?&lt;/p&gt;
&lt;p&gt;I'm not sure I agree with your assumption about the script using a non-unique incrementing key. Can you elaborate?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;-Brian&lt;/p&gt;
</description></item></channel></rss>