[英]How to increase database field value by 1 at refresh in PDO?
I search for this question but no one was able to solve my problem. 我搜索了这个问题,但没有人能够解决我的问题。 This is my query for to increase database fied value.
这是我要增加数据库fied价值的查询。 When I refresh page for first time then it automatically add 2 in one refresh but when I refresh second time then it doesn't update database value.
当我第一次刷新页面时,它将在一次刷新中自动添加2,但是当我第二次刷新时,它不会更新数据库值。
$stmt = $con->prepare("UPDATE mobile set view2=:view2+'1' WHERE id=:id");
$stmt->execute(array(':view2'=>$view2+1,':id'=>$id));
Help me. 帮我。 I'm new in PDO.
我是PDO的新手。
You don't need the parameter at all: 您根本不需要该参数:
UPDATE ... SET view2 = view2 + 1 WHERE ...
you can use a field in the record as a data source for updating any other field in the record, including itself. 您可以将记录中的字段用作数据源,以更新记录中的任何其他字段,包括本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.