1

我有 3 张桌子:

tbl_events --> 主键 = event_id

tbl_event_bids --> (event_id 里面没有主键)

tbl_users --> 主键 = u_id

我想获得这些领域:

tbl_events --> added_date

tbl_events --> bid_end_date

tbl_events --> event_date

tbl_event_bids --> bid_amount

tbl_users --> u_fname

tbl_users --> u_lname

没有任何错误,但数组为空。这段代码有错误吗?请帮忙...

public function get_confirmed_events($loged_user_id){

    $this->db->select(' tbl_events.event_name,
                        tbl_events.added_date,
                        tbl_events.bid_end_date,                            
                        tbl_events.event_date,

                        tbl_event_bids.bid_amount,

                        tbl_users.u_fname,
                        tbl_users.u_lname');

    $this->db->where('tbl_events.u_id', $loged_user_id);
    $this->db->where('tbl_events.closed_bid', 'N');

    $this->db->where('tbl_event_bids.bid_statues', 'W');        

    $this->db->join('tbl_event_bids', 'tbl_events.event_id = tbl_event_bids.event_id');
    $this->db->join('tbl_users', 'tbl_events.u_id = tbl_users.u_id');

    $data = $this->db->get('tbl_events');

    $confirmed_result = $data->result();

    return $confirmed_result;


}
4

2 回答 2

0

试试这个

public function get_confirmed_events($loged_user_id){
$this->db->select(' tbl_events.event_name,
                    tbl_events.added_date,
                    tbl_events.bid_end_date,                            
                    tbl_events.event_date,
                    tbl_event_bids.bid_amount,
                    tbl_users.u_fname,
                    tbl_users.u_lname');      
$this->db->join('tbl_event_bids', 'tbl_events.event_id = tbl_event_bids.event_id','LEFT');
$this->db->join('tbl_users', 'tbl_events.u_id = tbl_users.u_id','LEFT');
$this->db->where('tbl_events.u_id', $loged_user_id);
$this->db->where('tbl_events.closed_bid', 'N');
$this->db->where('tbl_event_bids.bid_statues', 'W'); 
$data = $this->db->get('tbl_events');
$confirmed_result = $data->result();
return $confirmed_result;
}

我已经使用了LEFT JOINif want to join with other 你可以在第三个参数中指定它join()也可以查看你的查询它的样子echo $this->db->last_query();

于 2013-07-11T08:58:54.150 回答
0

如果您使用连接,则必须使用 FROM,用于主表

public function get_confirmed_events($loged_user_id){

$this->db->select(' tbl_events.event_name,
                    tbl_events.added_date,
                    tbl_events.bid_end_date,                            
                    tbl_events.event_date,

                    tbl_event_bids.bid_amount,

                    tbl_users.u_fname,
                    tbl_users.u_lname');
$this->db->from('tbl_events');
$this->db->where('tbl_events.u_id', $loged_user_id);
$this->db->where('tbl_events.closed_bid', 'N');

$this->db->where('tbl_event_bids.bid_statues', 'W');        

$this->db->join('tbl_event_bids', 'tbl_events.event_id = tbl_event_bids.event_id','left');
$this->db->join('tbl_users', 'tbl_events.u_id = tbl_users.u_id','left');

$data = $this->db->get();

$confirmed_result = $data->result();

return $confirmed_result;

}

我希望它会帮助你。

于 2013-07-11T10:06:14.720 回答