CodeIgniter Forums
Active Record (Set) Browser issue? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Active Record (Set) Browser issue? (/thread-43533.html)



Active Record (Set) Browser issue? - El Forum - 07-15-2011

[eluser]Unknown[/eluser]
I am currently building a site that will capture page views and store them in a database. My code seems very straight-forward but the results are questionable...

When using Firefox 3.6.18 and Google Chrome 12.0.742.112 I end up with (2) page views added to the database rather than (1). In IE 8.0.7600.16385 it only increases the page views by (1), which is correct.

I can't figure out what the difference is but logging in/out doesn't change the results. I'm pretty new to CodeIgniter as well as MVC-logic in general so my debugging abilities are pretty limited.

Here's my Controller:

Code:
public function content()
        {
            $this->db->where('title', $this->uri->segment(3));
            $this->db->select('photo_uploads.title as title, photo_uploads.file_name as file_name, titles.title_id as title_id, titles.title_name as title_name, titles.description as description');
            $this->db->join('titles', 'photo_uploads.title = titles.title_id');

            $this->data->query = $this->db->get('photo_uploads');
            $this->data->content = 'hub/title_view';
            $this->load->view('layouts/standard_layout', $this->data);

            $this->load->model('Pageview_model');
            $this->Pageview_model->add_view();

        }

Here's the Model:

Code:
public function add_view() {

        $this->db->select('page_name');
        $this->db->where('page_name', uri_string());
        $pages = $this->db->get('pages');

        if(!$pages->num_rows() > 0) {
            $db_info = array (
                'page_name'     =>      uri_string(),
                'views'         =>      '1'
            );

            $this->db->insert('pages', $db_info);
        }
        else {

        $this->db->set('views', 'views+1', FALSE);
        $this->db->where('page_name', uri_string());
        $this->db->update('pages') ;
        }
        
    }

And the View:

Code:
<div id="content_area">
    <div class="top_ads">
        <div class="internal_ad"><a href="#"><img src="&lt;?= base_url();?&gt;images/internal_ad.png"></a></div>
        <div class="banner_ad"><img src="&lt;?= base_url();?&gt;images/banner_ad.jpg"></div>
    </div>
    
    <div class="category_head">
            
    </div>
    <div class="right_ad">
    <img src="&lt;?= base_url();?&gt;images/right_ad.jpg" />
    </div>
    &lt;?php foreach($query->result() as $row):?&gt;
    <div class="image_results">
        <img >file_name;?&gt;" height="333px" />
    </div>
    &lt;?php endforeach;?&gt;
    
</div>

To reiterate the problem:

Chrome and FF both add (2) page views to my database when the page is loaded. IE only adds (1) page view. I have no clue why...

Any help would be appreciated.