【发布时间】:2016-05-22 10:07:50
【问题描述】:
今天我在开发我的应用程序时遇到了问题。 我重组了我的数据库。
我有 3 个表格用于帖子、照片和帖子的标签。
我加入了另外两个表(照片、标签)。
我想查询前 3 个帖子,其中只有一个带有照片和标签的 SELECT,但结果中只显示第一行。
这是我的代码:
$this->db->select('owner, title, time, LEFT(content, 75) as content, category, url, price, county');
$this->db->from(POSTS_TABLE);
$this->db->join(PHOTOS_TABLE, PHOTOS_TABLE.'.post_id = '.POSTS_TABLE.'.url');
$this->db->join(TAGS_TABLE, TAGS_TABLE.'.post_url = '.POSTS_TABLE.'.url');
$this->db->order_by('time', 'desc');
$this->db->limit(3);
$query = $this->db->get();
$posts = $query->result();
我的数据库结构:
帖子表:
id, owner, title, content, url
tags 表:id、post_id(与 posts 表中的 url 列相同)、photo(指向照片的链接)
标签表:
id, post_url (same as the url column from the posts table), tag.
请帮忙。我怎样才能只用一个 SELECT 并显示正确的结果来实现这一点?
我不能使用 WHERE 子句,因为我不知道确切的 post_url
【问题讨论】:
标签: codeigniter mysqli