Jump to content

How to increase column by 1 using UPDATE?


galvin

Recommended Posts

I have code that I want to increase a column in my products table by 1.  So far I have this for my query...

 

 $sql = "UPDATE products SET orderclicks = (??????)
WHERE productid= '$productid'";

 

I just need help with that part in question marks.  In plain english, it would say "SET orderclicks = orderclicks+1"

 

I tried that and it didn't work.  I could easily run a query to get the value of 'orderclicks' first and then add one to that and then run another query to update it to the new value, but I imagine there is a way to do it in just ONE query, so it's more efficient

 

 

Link to comment
Share on other sites

That's correct -

In plain english, it would say "SET orderclicks = orderclicks+1"

 

If you tried that and it did not work, you would need to show the code necessary to reproduce the problem for anyone here to help with why it did not work.

 

Edit: And define ''it didn't work". What did happen? A blank page? A php error? A mysql error?

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