简体   繁体   English

表的列总和使用左连接返回null(codeigniter)

[英]sum of table's column return null (codeigniter) using left join

I have this query: 我有这个查询:

$get_similar = $this->db->select('product.ar_id, product.title, likes.id, SUM(likes.up) as vote');
$get_similar = $this->db->from('product');
$get_similar = $this->db->join('likes', 'likes.id = product.id', 'left');
$get_similar = $this->db->where("MATCH (product.title, product.introduction) AGAINST ('$search') group by product.id LIMIT 6", null, false);
$get_similar = $this->db->get();    

For each row I get vote = null ! 对于每一行,我都会获得vote = null It's supposed to return 0 for only the products that don't have votes! 对于没有投票的产品,应该返回0 Can you tell me where I made a mistake, please? 你能告诉我我哪里做错了吗?

I think your error is here: 我认为您的错误在这里:

$get_similar = $this->db->join('likes', 'likes.id = product.id', 'left');

you are joining likes.id with product.id, i think you want to join something like "likes.product_id" with "product.id" 您正在将likes.id与product.id结合在一起,我认为您想将诸如“ likes.product_id”与“ product.id”结合起来

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM