<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ActiveRecord and Zend_Paginator_Adapter_Interface</title>
	<atom:link href="http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/</link>
	<description>to obtain or receive from a source</description>
	<lastBuildDate>Mon, 08 Mar 2010 16:36:12 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Clay vanSchalkwijk</title>
		<link>http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/comment-page-1/#comment-389</link>
		<dc:creator>Clay vanSchalkwijk</dc:creator>
		<pubDate>Sat, 21 Nov 2009 21:28:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.derivante.com/?p=757#comment-389</guid>
		<description>You could work around it and just pass in the page and count per page into the construct and query for it up-front.  

public function __construct(page,itemperpage,conditions){
// get a subset:
SELECT SQL_CALC_FOUND_ROWS *
FROM table
WHERE somecondtion
LIMIT offset, itemperpage

// count of all records that would match query
SELECT FOUND_ROWS()

this-&gt;result = result;
this-&gt;count = count;
}

public function getItems()
{
return $this-&gt;result;
}

public function count()
{
return $this-&gt;count;
}

Not the most elegant solution, but it would work.</description>
		<content:encoded><![CDATA[<p>You could work around it and just pass in the page and count per page into the construct and query for it up-front.  </p>
<p>public function __construct(page,itemperpage,conditions){<br />
// get a subset:<br />
SELECT SQL_CALC_FOUND_ROWS *<br />
FROM table<br />
WHERE somecondtion<br />
LIMIT offset, itemperpage</p>
<p>// count of all records that would match query<br />
SELECT FOUND_ROWS()</p>
<p>this->result = result;<br />
this->count = count;<br />
}</p>
<p>public function getItems()<br />
{<br />
return $this->result;<br />
}</p>
<p>public function count()<br />
{<br />
return $this->count;<br />
}</p>
<p>Not the most elegant solution, but it would work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/comment-page-1/#comment-388</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Sat, 21 Nov 2009 21:03:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.derivante.com/?p=757#comment-388</guid>
		<description>my getitems is returning only a subset and my count represents total number of rows that match the query, i.e., &quot; count 789 rows --  now displaying 50 - 70&quot;
The most efficient way is to issue these 2 queries in succession:

// get a subset:
SELECT SQL_CALC_FOUND_ROWS * 
FROM table
WHERE somecondtion
LIMIT 49, 20

// count of all records that would match query
SELECT FOUND_ROWS()</description>
		<content:encoded><![CDATA[<p>my getitems is returning only a subset and my count represents total number of rows that match the query, i.e., &#8221; count 789 rows &#8212;  now displaying 50 &#8211; 70&#8243;<br />
The most efficient way is to issue these 2 queries in succession:</p>
<p>// get a subset:<br />
SELECT SQL_CALC_FOUND_ROWS *<br />
FROM table<br />
WHERE somecondtion<br />
LIMIT 49, 20</p>
<p>// count of all records that would match query<br />
SELECT FOUND_ROWS()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clay vanSchalkwijk</title>
		<link>http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/comment-page-1/#comment-386</link>
		<dc:creator>Clay vanSchalkwijk</dc:creator>
		<pubDate>Fri, 20 Nov 2009 16:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.derivante.com/?p=757#comment-386</guid>
		<description>This approach might not work for you without the ability to count independent of your query.  

getItems() should only return a subset since it is the slice that is displayed, therefore you can&#039;t mix count() which should represent the total number of records matching your query with the subset, it will always be wrong since the affected rows will always be your subset (the number or results per page($itemCountPerPage).

Unless you can create an independent counting function that can return the total number of rows you might be out of luck.  I&#039;m not sure how big your data set is, but querying everything just to get a count might not be feasible.</description>
		<content:encoded><![CDATA[<p>This approach might not work for you without the ability to count independent of your query.  </p>
<p>getItems() should only return a subset since it is the slice that is displayed, therefore you can&#8217;t mix count() which should represent the total number of records matching your query with the subset, it will always be wrong since the affected rows will always be your subset (the number or results per page($itemCountPerPage).</p>
<p>Unless you can create an independent counting function that can return the total number of rows you might be out of luck.  I&#8217;m not sure how big your data set is, but querying everything just to get a count might not be feasible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew warner</title>
		<link>http://www.derivante.com/2009/10/29/activerecord-and-zend_paginator_adapter_interface/comment-page-1/#comment-385</link>
		<dc:creator>andrew warner</dc:creator>
		<pubDate>Thu, 19 Nov 2009 21:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.derivante.com/?p=757#comment-385</guid>
		<description>&gt;&gt;The two methods the Zend_Paginator_Adapter_Interface expects are count() and getItems()

It appears that  count() is called first, which is a problem for me because I set the count value in  getItems() , so when count() is called, there&#039;s no count yet.
I&#039;m trying to adapt this for use outside the Zend Framework. 

[code]

public function getItems($offset, $itemCountPerPage)
{	
      /* modify sql; stick  the SQL_CALC_FOUND_ROWS  in there: */
       $sql_modified = substr_replace($this-&gt;sql, &#039; SQL_CALC_FOUND_ROWS &#039;, 6, 0)  . &quot; LIMIT $offset, $itemCountPerPage&quot;;
       $stmt = $this-&gt;pdo-&gt;prepare($sql_modified);
       $stmt-&gt;execute($params);

      /* set count property: */	
       $this-&gt;count = $this-&gt;pdo-&gt;query(&#039;SELECT FOUND_ROWS()&#039;)-&gt;fetchColumn(0);

       /* return data: */	
	return $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
}


public function count()
{
       return $this-&gt;count;	
}

[/code]</description>
		<content:encoded><![CDATA[<p>&gt;&gt;The two methods the Zend_Paginator_Adapter_Interface expects are count() and getItems()</p>
<p>It appears that  count() is called first, which is a problem for me because I set the count value in  getItems() , so when count() is called, there&#8217;s no count yet.<br />
I&#8217;m trying to adapt this for use outside the Zend Framework. </p>
<p>[code]</p>
<p>public function getItems($offset, $itemCountPerPage)<br />
{<br />
      /* modify sql; stick  the SQL_CALC_FOUND_ROWS  in there: */<br />
       $sql_modified = substr_replace($this-&gt;sql, ' SQL_CALC_FOUND_ROWS ', 6, 0)  . " LIMIT $offset, $itemCountPerPage";<br />
       $stmt = $this-&gt;pdo-&gt;prepare($sql_modified);<br />
       $stmt-&gt;execute($params);</p>
<p>      /* set count property: */<br />
       $this-&gt;count = $this-&gt;pdo-&gt;query('SELECT FOUND_ROWS()')-&gt;fetchColumn(0);</p>
<p>       /* return data: */<br />
	return $stmt-&gt;fetchAll(PDO::FETCH_OBJ);<br />
}</p>
<p>public function count()<br />
{<br />
       return $this-&gt;count;<br />
}</p>
<p>[/code]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->