添加+1到字段(点击计数器)

时间:2021-12-26 15:18:58

how do I add a +1 too the c_request field. every time I do and insert I want to add a 1 to the current number (ex. like a hit counter)

如何在c_request字段中添加+1。每次我这样做并插入时,我都想在当前数字上添加一个1(比如点击计数器)

mysql_query("INSERT INTO ed_names (com_id, c_date, c_time, c_type, c_request, c_by)
        VALUES ($id, CURRENT_DATE, CURRENT_TIME, '.($type == 'normal' ? 1 : 2).',0,$user)");     

$rid = mysql_insert_id();

2 个解决方案

#1


49  

mysql_query("UPDATE ed_names SET c_request = c_request+1 WHERE id = 'x'");

#2


2  

use update if you want to add to an existing, if not, just enter 1

如果您想要添加到现有的(如果不是),只需输入1。

INSERT INTO ed_names (com_id, c_date, c_time, c_type, c_request, c_by)
    VALUES ($id, CURRENT_DATE, CURRENT_TIME, '.($type == 'normal' ? 1 : 2).',1,$user) 

if you want to update you can do

如果你想要更新,你可以做

update ed_names set c_date = CURRENT_DATE, C_time = CURRENT_TIME, c_type = '.($type == 'normal' ? 1 : 2).''.($type == 'normal' ? 1 : 2).', c_request = c_request + 1, c_by = $user where com_id = $id

#1


49  

mysql_query("UPDATE ed_names SET c_request = c_request+1 WHERE id = 'x'");

#2


2  

use update if you want to add to an existing, if not, just enter 1

如果您想要添加到现有的(如果不是),只需输入1。

INSERT INTO ed_names (com_id, c_date, c_time, c_type, c_request, c_by)
    VALUES ($id, CURRENT_DATE, CURRENT_TIME, '.($type == 'normal' ? 1 : 2).',1,$user) 

if you want to update you can do

如果你想要更新,你可以做

update ed_names set c_date = CURRENT_DATE, C_time = CURRENT_TIME, c_type = '.($type == 'normal' ? 1 : 2).''.($type == 'normal' ? 1 : 2).', c_request = c_request + 1, c_by = $user where com_id = $id