0

My Sql query is like this

$view =  mysql_query ("SELECT domain,count(distinct session_id) as 
         views FROM `statistik` left join statistik_strippeddomains on 
         statistik_strippeddomains.id = statistik.strippeddomain WHERE
         `angebote_id` = '".(int)$_GET['id']."' and strippeddomain!=1 
         group by domain having count (distinct session_id) >
         ".(int)($film_daten['angebote_views']/100)."  order 
         count(distinct session_id$vladd) desc limit 25");

How can I write its Codeigniter Model I appreciate any Help

Reporter
  • 3,897
  • 5
  • 33
  • 47
Nora
  • 1
  • 1
  • http://stackoverflow.com/questions/6024800/codeigniter-table-join http://stackoverflow.com/questions/2975987/codeigniter-how-to-use-where-clause-and-or-clause http://stackoverflow.com/questions/8988268/count-group-by-with-active-record go through these questions, I think you would be able to find out your solution. – Sayantan Das Oct 04 '16 at 13:08

1 Answers1

1

try this

$this->db->select('statistik.domain,statistik.count(DISTINCT(session_id)) as views');
$this->db->from('statistik');
$this->db->join('statistik_strippeddomains', 'statistik_strippeddomains.id = statistik.strippeddomain', 'left'); 
$this->db->where('angebote_id',$_GET['id']);
$this->db->where('strippeddomain !=',1);
$this->db->group_by('domain');
$this->db->having('count > '.$film_daten['angebote_views']/100, NULL, FALSE);
$this->db->order_by('count','desc');
$this->db->limit('25');
$query = $this->db->get();

Comment me If you have any query.

Devidas Kadam
  • 944
  • 9
  • 19
  • Thanks for you help but I have no query. the problem is that "angebote_views" does not belongs to "statistik" table but other table which calls "abgebote". – Nora Oct 04 '16 at 13:41
  • yes I know this is not belongs to "statistik", But you have this value in `$film_daten` array. How it comes, I don't know. I just comparing it with `count` as you compared in your previous query. – Devidas Kadam Oct 05 '16 at 06:01