php - ZF2 - How to use SQL_CALC_FOUND_ROWS in columns()

855

I'm trying to use SQL_CALC_FOUND_ROWS in my query. But I can't create my query without AS Expression1

$select = $this->getSql()->select();
            $select->columns(array("*", new Expression(" SQL_CALC_FOUND_ROWS *")));
            $select->join( array ( 
                    'c2h' => 'site_category2help_topic' ), 'c2h.help_topic_id = site_help_topic.help_topic_id', array ( 
                    "*" ) );
            $select->where( " c2h.category_id = $categoryId " );
            $select->limit($limit);
            $select->offset($offset);

RESULT:

SELECT site_help_topic.*, SQL_CALC_FOUND_ROWS * *AS Expression1*, c2h.* 

FROM site_help_topic 

INNER JOIN site_category2help_topic AS c2h 

ON c2h.help_topic_id = site_help_topic.help_topic_id 

WHERE c2h.category_id = 5 LIMIT '15' OFFSET '0'

IT SHOULD BE :

SELECT site_help_topic.*, SQL_CALC_FOUND_ROWS *, c2h.* 

FROM site_help_topic 

INNER JOIN site_category2help_topic AS c2h 

ON c2h.help_topic_id = site_help_topic.help_topic_id 

WHERE c2h.category_id = 5 LIMIT '15' OFFSET '0'
100

Answer

Solution:

Sql\Select has an optionQUANTIFIER, you should be able to use that instead of giving it as a column name.

Similar to here How to use SQL_CALC_FOUND_ROWS with Zend\Db\TableGateway

People are also looking for solutions to the problem: php - Replace apostrophes in between brackets

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.