<?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: Zend Framework: Automatically fetch the grand total from a limit query</title>
	<atom:link href="http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/</link>
	<description></description>
	<lastBuildDate>Sun, 06 Jun 2010 03:25:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rafael (Aikanet)</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-45</link>
		<dc:creator>Rafael (Aikanet)</dc:creator>
		<pubDate>Tue, 26 May 2009 15:01:21 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-45</guid>
		<description>Great tutorial. You may want to add -&gt;reset(Zend_Db_Select::GROUP) to get your code working with a grouped query.

Regards Rafael</description>
		<content:encoded><![CDATA[<p>Great tutorial. You may want to add -&gt;reset(Zend_Db_Select::GROUP) to get your code working with a grouped query.</p>
<p>Regards Rafael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Temuri</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-6</link>
		<dc:creator>Temuri</dc:creator>
		<pubDate>Thu, 18 Sep 2008 14:44:22 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-6</guid>
		<description>Disregard my previous post, I didn&#039;t notice:

-&gt;columns(&#039;COUNT(1)&#039;);

Thanks again.</description>
		<content:encoded><![CDATA[<p>Disregard my previous post, I didn&#8217;t notice:</p>
<p>-&gt;columns(&#8216;COUNT(1)&#8217;);</p>
<p>Thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Temuri</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-5</link>
		<dc:creator>Temuri</dc:creator>
		<pubDate>Thu, 18 Sep 2008 13:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-5</guid>
		<description>Thanks a lot for the update. Will test it asap.

what is the practical importance of Zend_Db_Select::columns()? Does it have a connection to the topic of this article?</description>
		<content:encoded><![CDATA[<p>Thanks a lot for the update. Will test it asap.</p>
<p>what is the practical importance of Zend_Db_Select::columns()? Does it have a connection to the topic of this article?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-4</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Thu, 11 Sep 2008 02:47:55 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-4</guid>
		<description>Zend have now graciously added the Zend_Db_Select::columns() method. Might also want to check out Zend_Paginator.</description>
		<content:encoded><![CDATA[<p>Zend have now graciously added the Zend_Db_Select::columns() method. Might also want to check out Zend_Paginator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-3</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Tue, 26 Aug 2008 23:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-3</guid>
		<description>This is for ZF 1.5.3 which doesn&#039;t contain a Zend_Db_Select::assemble() method. Looks like I&#039;ll have to keep an eye out for this, thanks for the heads up.

Passing a null $name to Zend_Db_Select::from() seemed to be the only way to re-specify the column selection for an existing &quot;from&quot; clause.

As soon as 1.6 goes stable, I&#039;ll check it out and update this post with any changes.</description>
		<content:encoded><![CDATA[<p>This is for ZF 1.5.3 which doesn&#8217;t contain a Zend_Db_Select::assemble() method. Looks like I&#8217;ll have to keep an eye out for this, thanks for the heads up.</p>
<p>Passing a null $name to Zend_Db_Select::from() seemed to be the only way to re-specify the column selection for an existing &#8220;from&#8221; clause.</p>
<p>As soon as 1.6 goes stable, I&#8217;ll check it out and update this post with any changes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Temuri</title>
		<link>http://blog.philipbrown.id.au/2008/08/zend-framework-automatically-fetch-the-grand-total-from-a-limit-query/comment-page-1/#comment-2</link>
		<dc:creator>Temuri</dc:creator>
		<pubDate>Tue, 26 Aug 2008 21:27:00 +0000</pubDate>
		<guid isPermaLink="false">http://morecowbell.net.au/?p=3#comment-2</guid>
		<description>Thanks for sharing this!

Unfortunately, I haven&#039;t been able to use the code as-is, I was getting &quot;Select query cannot join with another table&quot; PDO exception.

I had to extend Zend_Db_Table_Select and add a method to custom set $_parts[] property:

class MySite_Db_Table_Select extends Zend_Db_Table_Select
{
    public function setPart($correlation, $part, $col)
    {
        array_push($this-&gt;_parts[$part], array($correlation, $col, null));
    }
}

And:

$select-&gt;reset(Zend_Db_Select::LIMIT_COUNT)
   -&gt;reset(Zend_Db_Select::LIMIT_OFFSET)
   -&gt;reset(Zend_Db_Select::ORDER)
   -&gt;reset(Zend_Db_Select::COLUMNS)
   -&gt;setPart($this-&gt;_name, Zend_Db_Select::COLUMNS, new Zend_Db_Expr(&#039;COUNT(1)&#039;));

Any idea why your code wasn&#039;t working? I am using ZF v1.6RC1.

It looks like the problem lies in &lt;b&gt;null&lt;/b&gt; argument of

-&gt;from(null, &#039;COUNT(1)&#039;);

Setting NULL creates problem in Zend\Db\Table\Select.php -&gt; assemble() method:


foreach ($fields as $columnEntry) {

    /**
     * $columnEntry is: array(false, Zend_Db_Expr(&#039;COUNT(1)&#039;), false). First &#039;false&#039; is
     * the result of passing NULL to $select-&gt;from().
     */
    list($table, $column) = $columnEntry;
    
    if ($column) {
        if (!isset($from[$table]) &#124;&#124; $from[$table][&#039;tableName&#039;] != $primary) {
            // We end up here because list() above sets $table to NULL.
            throw new Zend_Db_Table_Select_Exception(&#039;Select query cannot join with another table&#039;);
        }
    }
}

Now, passing the same table name to $select-&gt;from() as:

-&gt;from(&#039;myTable&#039;, &#039;COUNT(1)&#039;);

or

-&gt;from($this-&gt;_name, &#039;COUNT(1)&#039;);

creates a second element in $select-&gt;_parts[&#039;from&#039;] with a new correlation name &quot;myTable_2&quot;. This forces Zend_Db to join the same table again (using &quot;myTable_2&quot; alias) and that causes PDO exception saying that field name is ambiguous.

I am really curious to know how all that works for you. Maybe we could figure out correct way of doing it.

What&#039;s your ZF version?

Thanks</description>
		<content:encoded><![CDATA[<p>Thanks for sharing this!</p>
<p>Unfortunately, I haven&#8217;t been able to use the code as-is, I was getting &#8220;Select query cannot join with another table&#8221; PDO exception.</p>
<p>I had to extend Zend_Db_Table_Select and add a method to custom set $_parts[] property:</p>
<p>class MySite_Db_Table_Select extends Zend_Db_Table_Select<br />
{<br />
    public function setPart($correlation, $part, $col)<br />
    {<br />
        array_push($this-&gt;_parts[$part], array($correlation, $col, null));<br />
    }<br />
}</p>
<p>And:</p>
<p>$select-&gt;reset(Zend_Db_Select::LIMIT_COUNT)<br />
   -&gt;reset(Zend_Db_Select::LIMIT_OFFSET)<br />
   -&gt;reset(Zend_Db_Select::ORDER)<br />
   -&gt;reset(Zend_Db_Select::COLUMNS)<br />
   -&gt;setPart($this-&gt;_name, Zend_Db_Select::COLUMNS, new Zend_Db_Expr(&#8216;COUNT(1)&#8217;));</p>
<p>Any idea why your code wasn&#8217;t working? I am using ZF v1.6RC1.</p>
<p>It looks like the problem lies in <b>null</b> argument of</p>
<p>-&gt;from(null, &#8216;COUNT(1)&#8217;);</p>
<p>Setting NULL creates problem in Zend\Db\Table\Select.php -&gt; assemble() method:</p>
<p>foreach ($fields as $columnEntry) {</p>
<p>    /**<br />
     * $columnEntry is: array(false, Zend_Db_Expr(&#8216;COUNT(1)&#8217;), false). First &#8216;false&#8217; is<br />
     * the result of passing NULL to $select-&gt;from().<br />
     */<br />
    list($table, $column) = $columnEntry;</p>
<p>    if ($column) {<br />
        if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {<br />
            // We end up here because list() above sets $table to NULL.<br />
            throw new Zend_Db_Table_Select_Exception(&#8216;Select query cannot join with another table&#8217;);<br />
        }<br />
    }<br />
}</p>
<p>Now, passing the same table name to $select-&gt;from() as:</p>
<p>-&gt;from(&#8216;myTable&#8217;, &#8216;COUNT(1)&#8217;);</p>
<p>or</p>
<p>-&gt;from($this-&gt;_name, &#8216;COUNT(1)&#8217;);</p>
<p>creates a second element in $select-&gt;_parts['from'] with a new correlation name &#8220;myTable_2&#8243;. This forces Zend_Db to join the same table again (using &#8220;myTable_2&#8243; alias) and that causes PDO exception saying that field name is ambiguous.</p>
<p>I am really curious to know how all that works for you. Maybe we could figure out correct way of doing it.</p>
<p>What&#8217;s your ZF version?</p>
<p>Thanks</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! -->