简体   繁体   中英

mysql wrong column increment

what is wrong with this code?

$core->query("UPDATE games SET hits = hits + 1 WHERE id=".intval($id).";");

hits incerements by 2 and sometimes by 3! I mean for example hits = 3; when I call this function, hits will be 5 and sometimes 6! (add 2 and 3 instead 1).

mysql table type is MyISAM.

query function is:

function query($query) {


    $this->error="";
    $this->result=@$this->link->query($query);
    if(!$this->result) {
        $this->error=@$this->link->error;
        return FALSE;
    }

    return $this->result;
}

link is:

$link = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

The SQL code looks correct, so it must be the context that is causing the problem.

It is possible that you put the code in an element that gets called two or three times per page? If not explicitly, through an include or subroutine structure?

It seems that your query is correct but may be this function call for multiple time for same $id value. Please check this..

thanks

这是该页面上的Flash。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM