1

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.

3
  • 1
    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. Commented Jun 12, 2012 at 10:18
  • 1
    "message.user_id = network_users.user_id and message.user_id = network_users.user_id" why this ? Commented Jun 12, 2012 at 10:41
  • Hi, I have edited code above. Sorry for the mistake. Commented Jun 13, 2012 at 1:43

2 Answers 2

3

Use null instead of array()

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi although I found out problem but I try to use null instead of array() it also work well.
0

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. ^_^

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.