Welcome Guest, Not a member yet? Register   Sign In
count() and group_by equal 0 in database, but it show value equal 1 in view page
#1

[eluser]sovandy[/eluser]
As previous time I post a group_by(), I get another problem with it more.
I used group_by() to count the boo_id in lib_borrowings.
I used left join table lib_books and lib_borrowings. After that, I minus lib_books.boo_unit by count(lib_borrowings.boo_id).
It shows me 0 where books that are not borrowed yet in Mysql. However, it show me 1 in view page.
For example:

<code>
$this->db->select('lib_books.boo_id,

boo_title,
boo_unit,
COUNT(lib_books.boo_id)AS borrowed,
lib_books.status',FALSE);

$this->db->from('lib_books');
$this->db->join('lib_borrowings', 'lib_books.boo_id = lib_borrowings.boo_id','left');
$this->db->group_by('lib_books.boo_id');

</code>

In view page:

<code>
echo ($row['boo_unit']-$row['borrowed']);// in here it shows me $row['borrowed']=1
</code>

Note: The query above show me COUNT(lib_books.boo_id)=0 in PHPMYADMIN
#2

[eluser]Thorpe Obazee[/eluser]
Please add your sql dump.




Theme © iAndrew 2016 - Forum software by © MyBB