Jump to content

Recommended Posts

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

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

I believe you want to use the UPDATE feature

ie
[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 UPDATE

LITE...
Link to comment
https://forums.phpfreaks.com/topic/9972-increment-by-one-help/#findComment-37063
Share on other sites

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

[!--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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.