문제

I am trying the return with a new column named count. Here is my query. $userid is the paramter to pass in

        $select = $this->db->select()
            ->from('myfriend')
            ->where('fromid=?', $userid)
            ->join('user', 'user.userid = friends.toid')
            ->columns( new Zend_Db_Expr('Select count(*) where friends.toid = $userid as count'))
            ->order("id desc")
            ->limit(20);

I want to return a new column called count. where it will display number of rows where friends.toid = userid.

Seems to have some syntax error.

도움이 되었습니까?

해결책

You must use double quotes, not single quotes, so php can eval $userid, like "Select count(*) where friends.toid = $userid as count"

If you want to debug your query, you can always use:

echo $select->__toString()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top