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

 

 

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?

Archived

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

×
×
  • 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.