razorsese Posted April 3, 2012 Share Posted April 3, 2012 How I can increment a value into database ?! When I try whit my code it's replacing the data from mysql database not summing up $conn = new PDO( DBN, DB_USER, DB_PASS ); $sql = "UPDATE articles SET rating =:rating+1, totalv=:totalv+1 WHERE id = :id"; $st = $conn->prepare ( $sql ); $st->bindValue( ":rating", $this->rating, PDO::PARAM_INT ); $st->bindValue( ":id", $this->id, PDO::PARAM_INT ); $st->bindValue( ":totalv", $this->totalv, PDO::PARAM_INT ); $st->execute(); $conn = null; Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 3, 2012 Share Posted April 3, 2012 You can simplify it a lot by removing the variables for rating and total. you can increment a column by the column name. UPDATE bar SET foo = foo+1 Quote Link to comment Share on other sites More sharing options...
razorsese Posted April 3, 2012 Author Share Posted April 3, 2012 Thank you very much Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 3, 2012 Share Posted April 3, 2012 you're welcome! Mark as solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.