php - Selecting and ordering data from another table -
i have 2 tables topsites, , tophits.
tophits has id, account, useragent, ip referral, time topsites has id, name, email, url, return, active
everytime clicks link, stored in tophits table account being id topsites.
basically want echo out top hits day, figure need count how many hits there account=4 on time=today order top
here have far
$this->db->select('name, url'); $this->db->from('topsites'); $this->db->where('active' '1'); $this->db->join('tophits', 'tophits.id = topsites.account');
(this codeigniter)
i'm stuck. help?
try (untested)
when joining tables need specify in select statements table given field belongs to. ci default protects fieldnames backticks, if use sql methods in select/where statements, need give second parameter false
keep doing this, because malform intended sql methods. need add statement restrict today.
$this->db->select('topsites.name, topsites.url, count(tophits.id) hit_count',false); $this->db->from('topsites'); $this->db->where('active' '1'); $this->db->join('tophits', 'tophits.id = topsites.account'); $this->db->order_by('hit_count'); $query = $this->db->get();
Comments
Post a Comment