CodeIgniter Forums
How to count all data in field - 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: How to count all data in field (/showthread.php?tid=19722)



How to count all data in field - El Forum - 06-16-2009

[eluser]sovandy[/eluser]
Hello everybody,

I have a problem with codeigniter.I am a student studying web programming. Now, I'm doing a project called Library Management System. I hope everybody can help me. My problem is that:
I want to count the ID of Books that are borrowed to show in book_management.php. I know the syntax used to count the number of book_id, but I don know how to return it.

Everybody can help me by mail: [email protected]

Best regards,
Sovandy


How to count all data in field - El Forum - 06-16-2009

[eluser]bretticus[/eluser]
How 'bout me just replying here instead?

You can simply use SQL to get a count. Such as
Code:
SELECT COUNT(*) AS borrowed_result FROM borrowed_books

to get this in Code Igniter, you can use query and a way to get a query result like:

Code:
$query = $this->db->query('SELECT COUNT(*) AS borrowed_count FROM borrowed_books');
$row = $query->row();
echo $row->borrowed_count;

Alternatives might be:
Code:
$query = $this->db->get('borrowed_books');
echo $query->num_rows();

...or just...
Code:
echo $this->db->count_all('borrowed_books');



How to count all data in field - El Forum - 06-16-2009

[eluser]manojchakri[/eluser]
echo $this->db->count_all('borrowed_books');

Nicely explained