count() and group_by equal 0 in database, but it show value equal 1 in view page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: count() and group_by equal 0 in database, but it show value equal 1 in view page (/showthread.php?tid=19916) |
count() and group_by equal 0 in database, but it show value equal 1 in view page - El Forum - 06-22-2009 [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 count() and group_by equal 0 in database, but it show value equal 1 in view page - El Forum - 06-22-2009 [eluser]Thorpe Obazee[/eluser] Please add your sql dump. |