【发布时间】:2017-06-22 07:54:59
【问题描述】:
我正在使用 Codeigniter,我想要做的是当用户将图片上传到图库时,第一个上传的图片应该被选为个人资料图片。
我的数据库结构
项目表
| id | slug | user_id | post_date |
| 12 | test | 111 | 12/5/2017 |
项目库
| gallery_id | item_id | image |
| 121 | 12 | profile.png | -- i want this record selected
| 122 | 12 | gallery.png |
我使用此代码从图库表中选择随机图片。
public function shopItems($id) {
$this->db->select("*,MIN(item_gallery.gallery_id)");
$this->db->from('items');
$this->db->join('item_gallery', 'items.id = item_gallery.item_id', 'left');
$this->db->where('items.user_id', $id);
$this->db->order_by('items.post_date', 'Desc');
$this->db->group_by("item_gallery.item_id");
$query = $this->db->get();
return $query->result();
}
【问题讨论】:
标签: mysql codeigniter activerecord codeigniter-3