Dragen Posted April 20, 2007 Share Posted April 20, 2007 How do I increment an int variable by 1, in a table. I'm currently using this code: <?php $clicks = $row['clicks']+1; $result = mysql_query("UPDATE downloads SET clicks = '$clicks' WHERE down_id = '$id'") or die (mysql_error()); ?> which works, but it there a way of having clicks increment without having to use another variable? such as: [code]SET clicks = clicks++ I have tried the above, but it doesn't work.. I've tried searching for it and just found lots of sites about auto increment table types.. :-\ Thanks[/code] Link to comment https://forums.phpfreaks.com/topic/47870-solved-increment-value-in-table/ Share on other sites More sharing options...
Onle Posted April 20, 2007 Share Posted April 20, 2007 As a best practice I would remove the ' from the values if they are both integers which the appear to be. Second $result = mysql_query("UPDATE downloads SET clicks = ".$row['clicks'] ." + 1 WHERE down_id = $id") Link to comment https://forums.phpfreaks.com/topic/47870-solved-increment-value-in-table/#findComment-233886 Share on other sites More sharing options...
jitesh Posted April 20, 2007 Share Posted April 20, 2007 update tablename set fieldname = fieldname + 1; Link to comment https://forums.phpfreaks.com/topic/47870-solved-increment-value-in-table/#findComment-233892 Share on other sites More sharing options...
Dragen Posted April 20, 2007 Author Share Posted April 20, 2007 Thanks all. Worked perfectly... Link to comment https://forums.phpfreaks.com/topic/47870-solved-increment-value-in-table/#findComment-233896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.