Welcome Guest, Not a member yet? Register   Sign In
Simple DB call being made twice?
#1

[eluser]WoolyG[/eluser]
Hi,

In one of my models, I am carrying out a simple integer incrementation script:

Model:
Code:
function increment_product_views($product_id){
        $this->db->query("
        UPDATE products SET products.views=(views + 1) WHERE products.product_id='$product_id' LIMIT 1
        ");        
    }

Controller:
Code:
$this->Products_model->increment_product_views($product_id);

However, for some reason the function is being called twice, making a bit of a mess of my stats. I've run the SQL query on its own, and it increments just once, and I've echoed the query from the model, to see how many times it's printed on the page, and it shows only once.

However, the number is being incremented by 2 each time. I'm positive that there's nobody else viewing this page at the time, which would also cause this.

Has anyone else seen this behaviour? Can anyone help out?

Weird one.


Thanks
WoolyG
#2

[eluser]WanWizard[/eluser]
Activate logging, and check if you don't have multiple requests.

A common mistake is for example an image on a page that doesn't exist, and if you use an .htaccess that relies of file existence, get rewritten to index.php.




Theme © iAndrew 2016 - Forum software by © MyBB