首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选择View Item返回空(Checklist Link )

选择View Item返回空(Checklist Link )
EN

Stack Overflow用户
提问于 2016-04-27 20:53:51
回答 1查看 48关注 0票数 0

如果查询是在核对表中,则显示特定项的查询似乎有问题。我目前有多个表,主要是用户,字符,系列,项目和清单。字符和序列链接到项表中,而用户和项在检查表中链接。

这样做的方式是,如果用户登录到核对表之外的项上按下按钮,则此项目将添加到核对表中(如果在“可删除”检查表中,则显示“删除”按钮)。

我目前的工作如下:

  • 如果用户未登录并在主页上登录:用X显示所有项目
  • 如果用户登录并登录在主页上:显示所有不在 带X的核对表和在检查表中的所有项 滴答。
  • 如果用户未登录单击视图,则有关项的详细信息如下: 使用X显示有关项目的更多详细信息(单个项目页)

What I am trying to achieve now is if a user is logged in and clicks view more details, to show the individual item page with a X or Tick (Depending if in checklist table). This is kinda working as items which are in the checklist table can be selected to view the individual item page when logged in. However if the item is not in the checklist table and the user is logged in, nothing is returned back. I am at a total loss how to resolve this and am trying to avoid copying all the items into the checklist table with an additional field (Y/N).

如果用户登录,而我使用的是codeigniter,则使用这个查询获取特定的项信息:

代码语言:javascript
复制
$this->db->select('item.item_id AS item_id, item.item_image AS item_image, line.line_name AS line_name, series.series_name AS series_name, character.character_name AS character_name, checklist.checklist_id AS checklist_id');
$this->db->from('item');
$this->db->join('line', 'item.line_id = line.line_id', 'left');
$this->db->join('series', 'item.series_id = series.series_id', 'left');
$this->db->join('character', 'item.character_id = character.character_id', 'left');
$this->db->join('checklist', 'checklist.item_id = item.item_id', 'left');
$this->db->where('checklist.users_id', $user_id);
$this->db->or_where('checklist.users_id IS NULL'); // Also tried without this line
$this->db->where('item.item_id', $item_id);
$query = $this->db->get();
return $query->row_array();

当其他三个查询按预期运行时,任何帮助都是很好的,除了返回($checklist.users_id->checklist.users_id为NULL)之外,其他三个查询都是相同的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-27 22:35:07

看来我找到解决办法了。我将条目ID移到联接下,将or_where更改为where,将where更改为or_where。因此,工作代码如下:

代码语言:javascript
复制
$this->db->select('item.item_id AS item_id, item.item_image AS item_image, line.line_name AS line_name, series.series_name AS series_name, character.character_name AS character_name, checklist.checklist_id AS checklist_id');
$this->db->from('item');
$this->db->join('line', 'item.line_id = line.line_id', 'left');
$this->db->join('series', 'item.series_id = series.series_id', 'left');
$this->db->join('character', 'item.character_id = character.character_id', 'left');
$this->db->join('checklist', 'checklist.item_id = item.item_id', 'left');
$this->db->where('item.item_id', $item_id);    
$this->db->or_where('checklist.users_id', $user_id);
$this->db->where('checklist.users_id IS NULL');    
$query = $this->db->get();
return $query->row_array();

不完全确定or_where是否应该在这个位置之上,但是它也在为我所需要的东西而工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36900683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档