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
https://forums.phpfreaks.com/topic/100616-solved-mysql-query-question/
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!! ???

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.