Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add +1 to field (hit counter)

Tags:

mysql

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)

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();
like image 514
acctman Avatar asked Nov 18 '10 11:11

acctman


2 Answers

mysql_query("UPDATE ed_names SET c_request = c_request+1 WHERE id = 'x'");
like image 140
tbleckert Avatar answered Oct 31 '22 15:10

tbleckert


use update if you want to add to an existing, if not, just enter 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
like image 2
Kennethvr Avatar answered Oct 31 '22 17:10

Kennethvr