您好,我有以下搜索功能来查找信息:
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();
}
我如何将另一个表 say 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>
最佳答案
您可以在查询中使用 join:
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();
}
希望对你有所帮助....
关于php - 如何在 Codeigniter 中加入表以进行搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471861/