选择“查看项目”将返回 Null(清单链接表)


Selecting View Item returns Null (Checklist Link Table)

>如果查询在清单表中显示特定项目,我似乎遇到了问题。我目前有多个表格,主要是用户,角色,系列,项目和清单。角色和系列链接到项目表中,而用户和项目在清单表中链接。

其工作方式是,如果用户登录时对不在清单表中的项目按下按钮,则该项目将被添加到清单表中(如果在清单中可以,将显示删除按钮)。

我目前的工作如下:

  • 如果用户未登录并在主页上:显示所有带有十
  • 如果用户已登录并在主页上:显示所有不在
    带有 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).

这是我用来获取特定项目信息的查询,如果用户登录了我正在使用代码点火器:

$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();

任何帮助都非常棒,因为其他三个查询正在按预期运行,除了返回($query->result_array)和添加的or_where(checklist.users_id为空)之外,它们与上述相同。

似乎我找到了解决方法。我将项目 ID 移动到联接下的位置,将or_where更改为位置以及or_where位置。所以工作代码如下:

$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是否应该高于位置,但它也适用于我需要的东西。