如果查询是在核对表中,则显示特定项的查询似乎有问题。我目前有多个表,主要是用户,字符,系列,项目和清单。字符和序列链接到项表中,而用户和项在检查表中链接。
这样做的方式是,如果用户登录到核对表之外的项上按下按钮,则此项目将添加到核对表中(如果在“可删除”检查表中,则显示“删除”按钮)。
我目前的工作如下:
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();当其他三个查询按预期运行时,任何帮助都是很好的,除了返回($checklist.users_id->checklist.users_id为NULL)之外,其他三个查询都是相同的。
发布于 2016-04-27 22:35:07
看来我找到解决办法了。我将条目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是否应该在这个位置之上,但是它也在为我所需要的东西而工作。
https://stackoverflow.com/questions/36900683
复制相似问题