【发布时间】:2015-05-16 09:12:23
【问题描述】:
我在 property_address 表中的列表表 1 中有一条记录,在 property_images 表中有三张图像,它们属于列表表中的那条记录。现在我实际上想要返回单行包含所有图像。但是我得到的是 3 行,因为属性图像表中的每个图像都有 3 个图像,所以它会创建一个新行。
我有三张桌子
- 上市
- property_address
- property_images
这是架构。
这里是模型函数。
public function get_listing($where)
{
$this->db->select('dl.*,pi.*,ps.*');
$this->db->from('listing as dl');
$this->db->join('property_address as ps','ps.property_add_id=dl.prop_id');
$this->db->join('property_images as pi','pi.listing_id=dl.prop_id','right');
if(!empty($where))
{
$this->db->where($where);
}
$query=$this->db->get();
return $query->result();
}
这是控制器。
public function testin()
{
$data=$this->dba->get_listing(array('dl.prop_id'=>2));
echo "<pre>";
print_r($data);
echo "</pre>";
}
【问题讨论】:
-
您可以在控制器中查询后执行
echo $this->db->last_query();,以查看MySQL查询,并使用该查询在phpmyadmin中执行以查看查询是否有问题! -
查询运行完美问题是多条记录相同但图像不同
-
结果是预期的。你在
property_images有 3 行,所以结果将是 3。你应该提供你想要的一行的例子。
标签: php mysql codeigniter join