Jump to content

[SOLVED] MySQL Query question


Pioden

Recommended Posts

I want to increment some values in a MySQL (5) db. The basic idea is where values in column X are greater than $somenumber the values in column X will be incremented by 1 ... For example if $somenumber = 5 all the values in column X which are greater than 5 have one added to them.

 

I'm pretty certain I can do this with a series of queries and PHP processing but that feels like a horribly clunky way of doing it. Is there an SQL query/command which will help? I was thinking along the lines of:

 

SQL = "UPDATE table

SET column_x +1

WHERE column_x >5" ;

 

Is this possible? My MySQL bible doesn't say much about this (or I'm looking in the wrong place!).

 

TIA

 

Huw

Link to comment
Share on other sites

Thanks for that. Not quite getting it though :-( I wrote this - which looks right to me but throws a syntax error

 

$sql = "UPDATE navigation

SET (pageorder +1)

WHERE pageorder >='$newpageorder'

AND page_uid !='$sent_page_uid'

";

 

Any ideas where I went wrong? It looks right to me!! ???

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.