redarrow Posted May 19, 2006 Share Posted May 19, 2006 Advance thank you.In my database i have added a field called clicks, each time a user submits new data i want that table clicks increment by one but haveing trouble please help.[code]if($_POST(["submit"]) {$db=mysql_connect("localhost");mysql_select_db("promotor", $db);$query="INSERT INTO users VALUES('$id','$password','$score','$clicks');$result=mysql_query($query);while($clicks=mysql_fetch_assoc($result)) {$clicks++;}[/code] Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/ Share on other sites More sharing options...
redarrow Posted May 19, 2006 Author Share Posted May 19, 2006 Does this make sence cheers.I wonder if theres a way to get the query to increment by one.[code]if($_POST(["submit"])) {$db=mysql_connect("localhost");mysql_select_db("promotor", $db);$query="INSERT INTO users VALUES('$id','$password','$score','$clicks' where clicks='$clicks'+1);$result=mysql_query($query);}[/code] Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37061 Share on other sites More sharing options...
litebearer Posted May 19, 2006 Share Posted May 19, 2006 I believe you want to use the UPDATE featureie[code]$result = mysql_query("UPDATE USERS SET click=click+'1' WHERE user = $some_user_id") or die(mysql_error()); [/code]might not be EXACTLY correct but it gives you the general idea - simply look in th ephp/mysql manual for UPDATELITE... Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37063 Share on other sites More sharing options...
redarrow Posted May 19, 2006 Author Share Posted May 19, 2006 sorry silly me the update was it, I need to no if the clicks=$clicks+'1' does the increment and keeps adding a 1 one to the total cheers. Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37064 Share on other sites More sharing options...
litebearer Posted May 19, 2006 Share Posted May 19, 2006 yep...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]If you access a column from tbl_name in an expression, UPDATE uses the current value of the column. For example, the following statement sets the age column to one more than its current value: UPDATE persondata SET age=age+1;[/quote][a href=\"http://dev.mysql.com/doc/refman/5.0/en/update.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/update.html[/a]Lite... Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37068 Share on other sites More sharing options...
redarrow Posted May 19, 2006 Author Share Posted May 19, 2006 [!--quoteo(post=375129:date=May 19 2006, 03:59 AM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 19 2006, 03:59 AM) [snapback]375129[/snapback][/div][div class=\'quotemain\'][!--quotec--]yep...[a href=\"http://dev.mysql.com/doc/refman/5.0/en/update.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/update.html[/a]Lite...[/quote]Thank you so much.I read that topic a while back and got the book but forgot cheers.[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]soved[!--sizec--][/span][!--/sizec--]ps. Thank you for your time. Link to comment https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.