1
  Table : sc_message 
  ______________________________________________________________________
 |message_id | message_sender_id | message_receiver_id | message_content|
 ------------------------------------------------------------------------  

Table : sc_user 
  _____________________
 | user_id | user_name |
 ----------------------- 

Table : sc_message_slave

| message_slave_id | message_slave_sender_id | message_slave_receiver_id | message_slave_content | message_slave_sent_on |

 $Query_1 = $this ->select()
                  ->from(array('msg' => 'sc_message'), array('msg.message_sender_id', 'msg.message_receiver_id', 'msg.message_content', 'msg.message_sent_on'))
                  ->join(array('usr' => 'sc_user'), 'msg.message_sender_id = usr.user_id', array('usr.user_name as sender_name'))
                  ->where('msg.message_id = ?',$message_id)
                  ->setIntegrityCheck(false);


 $Query_2 = $this ->select()
                     ->from(array('msg_slv' => 'sc_message_slave'), array('msg_slv.message_slave_sender_id', 'msg_slv.message_slave_receiver_id','msg_slv.message_slave_content', 'msg_slv.message_slave_sent_on'))
                     ->join(array('usr' => 'sc_user'), 'msg_slv.message_slave_sender_id = usr.user_id', array('usr.user_name as sender_name'))
                     ->where('msg_slv.message_id = ?',$message_id)
                     ->setIntegrityCheck(false);            
 $select = $this ->select()
                    ->union(array($Query_1, $Query_2))
                    ->order('msg.message_sent_on')
                    ->setIntegrityCheck(false);

它给了我这样的警告,并且执行在那里停止..

Warning: Invalid use of table with UNION in E:\wamp\www\social_site\library\Zend\Db\Select.php on line 1222 

你能告诉我查询有什么问题吗?

4

1 回答 1

1

既然你有一个你在哪里做联合的命令,你可能会遇到这个问题:

http://framework.zend.com/issues/browse/ZF-4338

他们不会解决问题,您可以阅读原因,但有人发布了解决方法。

$select_1 = $db->select()->...;
$select_2 = $db->select()->...;

$main_select = $db->select()->union( array(  '('.$select_1.')',  '('.$select_2.')' ) );
于 2012-05-13T04:42:26.933 回答