Welcome Guest, Not a member yet? Register   Sign In
Mutiple SQL count() from several tables
#9

[eluser]oliviermarian[/eluser]
hello,
is there a proper way to code this using active record CI code, or is it better to use the sql query syntax ?

I mean:
Code:
$sql="SELECT users.name, user.address, users.mail,
COUNT(pm.*) AS total_pm, COUNT(posts.*) AS total_posts, COUNT(login.*) AS total_login
FROM users
INNER JOIN pm ON users.id=pm.user
INNER JOIN posts ON users.id=posts.user
INNER JOIN login ON users.id=login.user
WHERE id=102";
$data['query'] = $this->db->query($sql);

or something like
Code:
this->db->select('users.name, user.address, users.mail');
$this->db->from('users');
$this->db->join("pm", "users.id=posts.user");
$this->db->join("posts", "users.id=posts.user");
$this->db->join("login", "users.id=login.user");
$this->db->stop_cache();
$total = $this->db->count_all_results();
$query = $this->db->get();
$this->db->flush_cache();
return $query->result();

1 - I don't know if it works
2 - Is it worth trying once we have the sql query working ?


Messages In This Thread
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 12:57 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 03:18 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 03:56 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 04:23 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 04:26 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 05:20 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 08:34 PM
Mutiple SQL count() from several tables - by El Forum - 02-12-2008, 04:41 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:04 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:25 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:38 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB