Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

increasing all values in a column 2

Status
Not open for further replies.

roycrom

Programmer
Aug 2, 2002
184
GB
Hi all,

This should be really simple but I can't seem to find the syntax,

I have a simple table with 2 fields. Weeknumber and homepage.

Weeknumber starts at 1 and goes up to 40, I am using php to redirect to a different homepage every week,

I am inserting from a text file and once in the database i want to increase every weeknumber by four so i get weeknumber 4 to 43 instead of 1 to 40.

Thanks in advance

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
lol it took me a while to figure the code out, i think you meant this, my table is called homepages
Code:
update homepages set weeknumber = weeknumber + 3
my only prblem with this is that I had the weeknumber as unique so as soon as it tries to add three on to week 1 it becomes week 4 which is already in my table so it falls over straight away. Is there a way around this or a way to take unique off the table, update the table then put unique back in.

I have tried this in phppgadmin but cant seem to take the unique out.

For now I will just drop thhe table and recreate it without the unique weeknumber.

Thanks for your reply.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
How about:
[tt]
update homepages
set weeknumber = weeknumber + 3
order by weeknumber desc
[/tt]
 
I'm gonna give you a star for that r937 bacause that is just very clever. Thinking outside the box [thumbsup2]

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top