Welcome Guest, Not a member yet? Register   Sign In
How to count all data in field
#1

[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
#2

[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');
#3

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

Nicely explained




Theme © iAndrew 2016 - Forum software by © MyBB