0

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.

Slay
  • 1,285
  • 4
  • 20
  • 44

1 Answers1

0

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()
Daniel L.
  • 5,060
  • 10
  • 36
  • 59