Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

increment by one help

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]


Share this post


Link to post
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]

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.