选择查看项目 returns Null(清单 Link Table)
Selecting View Item returns Null (Checklist Link Table)
我似乎在查询显示清单中的特定项目时遇到问题 table。我目前有多个 table,主要是用户、角色、系列、项目和清单。角色和系列链接到项目 table,而用户和项目链接到清单 table。
其工作方式是,如果登录用户针对不在清单 table 中的项目按下按钮,则该项目将添加到清单 table(如果在清单中可以,将显示一个删除按钮。
我目前的工作如下:
- 如果用户未登录且位于主页面上:显示所有带有
X
- 如果用户已登录并位于主页面上:显示所有不在
中的项目
清单 table 带有 X,清单 table 中的所有项目带有
打勾
- 如果用户未登录点击查看有关项目的更多详细信息:
显示带有 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 的用户登录时用来获取特定项目信息的查询:
$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();
任何帮助都会非常有用,因为其他三个查询是 运行 预期的,除了 return ($query->result_array 之外与上面的相同) & 添加了 or_where (checklist.users_id IS NULL).
看来我找到了解决方法。我移动了连接下的项目 ID,将 or_where 更改为 where,将 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 是否应该在 where 之上,但它也能满足我的需要。
我似乎在查询显示清单中的特定项目时遇到问题 table。我目前有多个 table,主要是用户、角色、系列、项目和清单。角色和系列链接到项目 table,而用户和项目链接到清单 table。
其工作方式是,如果登录用户针对不在清单 table 中的项目按下按钮,则该项目将添加到清单 table(如果在清单中可以,将显示一个删除按钮。
我目前的工作如下:
- 如果用户未登录且位于主页面上:显示所有带有 X
- 如果用户已登录并位于主页面上:显示所有不在
中的项目 清单 table 带有 X,清单 table 中的所有项目带有
打勾 - 如果用户未登录点击查看有关项目的更多详细信息:
显示带有 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 的用户登录时用来获取特定项目信息的查询:
$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();
任何帮助都会非常有用,因为其他三个查询是 运行 预期的,除了 return ($query->result_array 之外与上面的相同) & 添加了 or_where (checklist.users_id IS NULL).
看来我找到了解决方法。我移动了连接下的项目 ID,将 or_where 更改为 where,将 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 是否应该在 where 之上,但它也能满足我的需要。