Welcome Guest, Not a member yet? Register   Sign In
Help with query: Join, Limit and Count total rows?
#5

[eluser]Armchair Samurai[/eluser]
This will retrieve the first 20 posts with motorcycle tag as well as give the total number of 'motorcycle' posts contained in the database.

Code:
$data = new stdClass;

$this->db->start_cache();
    $this->db->from('posts p');
    $this->db->join('users u', 'p.userid = u.id');
    $this->db->join('tagmap tm', 'p.id = tm.post_id');
    $this->db->join('tags t', 'tm.tag_id = t.id');
    $this->db->where('t.name', 'motorcycles');
$this->db->stop_cache();

$data->count = $this->db->count_all_results();

$this->db->select('p.*, u.username');
$this->db->limit(20);

$query = $this->db->get();
$data->posts = $query->result();

$this->db->flush_cache();
return $data;


Messages In This Thread
Help with query: Join, Limit and Count total rows? - by El Forum - 11-17-2008, 09:46 PM
Help with query: Join, Limit and Count total rows? - by El Forum - 11-17-2008, 10:38 PM
Help with query: Join, Limit and Count total rows? - by El Forum - 11-17-2008, 10:52 PM
Help with query: Join, Limit and Count total rows? - by El Forum - 11-18-2008, 12:49 AM
Help with query: Join, Limit and Count total rows? - by El Forum - 11-18-2008, 01:15 AM
Help with query: Join, Limit and Count total rows? - by El Forum - 11-18-2008, 01:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB