php - sum of table's column return null (codeigniter) using left join

975

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 getvote = null! It's supposed to return0 for only the products that don't have votes! Can you tell me where I made a mistake, please?

370

Answer

Solution:

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"

People are also looking for solutions to the problem: PHP Sorting by turns

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.