1
votes

I have a problem with zend when I select data from DB. In my query I don't want select any column from table that I join with another table. I use array() in third parameter. But when I do this:

$sql = $db->select();
    $sql->from( "message", "message.message_id" )

        ->->join("network_users","message.network_id = network_users.network_id and message.user_id = network_users.user_id","network_users.network_id") //no get column
        ->join("users","message.user_id = users.user_id",array()) //no get column
        ->where( "message.network_id = :network_id" )
        ->where( "message.del_flg = 0" )
        ->where( "network_users.del_flg = 0" )
        ->where( "users.del_flg = 0" )
        ->order( "message.regist_date DESC" );

 $ary[':network_id']   = $network_id;
 $ret = $db->fetchAll($sql, $ary);

return empty($ret[0]["user_id"]) ? array():$ret;

I always get result is array(0) {}

When I get least one column in each table, it response correct result.

Any idea for my problem????

Thanks for any help.

2
It looks like the first where clause. You've passed in an parameter name 'network_id' and not a value. Do an echo of $sql to see what is being generated. - Richard Parnaby-King
"message.user_id = network_users.user_id and message.user_id = network_users.user_id" why this ? - Mr Coder
Hi, I have edited code above. Sorry for the mistake. - LeO Pham

2 Answers

3
votes

Use null instead of array()

So it would look like this: ->join("users","message.user_id = users.user_id",null)

0
votes

I found the problem, problem is I used return empty($ret[0]["user_id"]) ? array():$ret; instead of return empty($ret[0]["message_id"]) ? array():$ret;.

That is reason I always receive array(0) {}.

Thanks for help. ^_^