我使用两个表来保存有关汽车的信息。在第一个表格中有关于汽车制造商等的信息,第二个表格包含每辆车的图像。我的表是这样的:不同的mysql结果 - codeigniter
car_information car_images
--------------- ---------
id | 2 car_id 2 | img1
car_make | Fiat car_id 2 | img2
color | Blue car_id 2 | img3
etc ....
正如你可以看到每个车有三幅图像。
这里是查询我是用来获取结果;
$this->db->select('
c.id,
c.car_make,
c.car_color,
ci.image
');
$this->db->from('car_information c');
$this->db->join('car_images ci', 'ci.car_id = c.id', 'left');
return $this->db->get();
一切工作正常,但存在的问题我真的面对的是,结果是重复的。
例如:
2 Fiat Blue img1
2 Fiat Blue img2
2 Fiat Blue img3
3 BMW white img4
3 BMW white img5
什么这样做的结果是这样的
2 Fiat Blue img1 | img 2 | img 3
我想在单行的所有信息。 我知道我可以给你两个疑问,但我想知道如何处理单个问题?
是否有这个要求的原因? – DarkSquirrel42 2011-05-08 12:39:17