嗨,我有以下搜索可用于查找信息的功能:

    function get_search(){
        $property_location = $this->input->post('property_location');
        $property_bedroom = $this->input->post('property_bedroom');
        $property_bathroom = $this->input->post('property_bathroom');
        $property_status = $this->input->post('property_status');
        $property_type = $this->input->post('property_type');

        $this->db->like('property_location',$property_location);
        $this->db->like('property_beds',$property_bedroom);
        $this->db->like('property_bath',$property_bathroom);
        $this->db->like('property_state',$property_status);
        $this->db->like('property_type',$property_type);
        $query = $this->db->get('property');
        error_log($this->db->last_query());
    return $query->result();
}


我将如何联接另一个表,将property_images加入搜索中,以便将数据包括在结果中?

这是我的看法:

<div class="container">
<div class="page-header">
    <h4>Your search returned the following result(s):</h4>
</div>
<?php foreach ($results as $item): ?>
<div class="row">
        <div class="col-md-3">
            <div class="thumbnail">
                <img
                    src="<?php echo base_url() . 'data/images/property_images/' . $item->image_name; ?>"
                    class="img-responsive">
            </div>
        </div>
        <div class="col-md-9">
            <h4 style="margin-top: 0;">
                <a href="/property/view/<?php echo $item->property_slug;?>"><?php echo $item->property_name; ?></a>
            </h4>
            <p><?php echo $item->property_description;?></p>
            <p>Location: <?php echo $item->property_location ?> | Price: R<?php echo $item->property_price ?></p>
        </div>
</div>
    <hr>
<?php endforeach; ?>
</div>

最佳答案

您可以在查询中使用连接:

     function get_search(){
        $property_location = $this->input->post('property_location');
        $property_bedroom = $this->input->post('property_bedroom');
        $property_bathroom = $this->input->post('property_bathroom');
        $property_status = $this->input->post('property_status');
        $property_type = $this->input->post('property_type');

        $this->db->like('property_location',$property_location);
        $this->db->like('property_beds',$property_bedroom);
        $this->db->like('property_bath',$property_bathroom);
        $this->db->like('property_state',$property_status);
        $this->db->like('property_type',$property_type);
        $this->db->join('property_images','property.property_image_id=property_images.property_image_id');   //add this line in your code
        $query = $this->db->get('property');
        error_log($this->db->last_query());
    return $query->result();
}


希望对您有帮助。

10-07 19:38
查看更多