PDA

View Full Version : Adding to mysql rows


Zangeel
05-24-2009, 12:52 PM
OK so i want to increase the views on a video site I have, where if they have small amounts of views i want to boost em up a bit..

i was thinking in mysql

UPDATE `views` FROM `vids` ...................... WHERE `views` < '1000'

But setting them to say 1500 makes all the views the same, but i want to just ADD maybe 500 views, how can i do that

Old Pedant
05-24-2009, 07:57 PM
LOL! Cheating, huh??

You could do

UPDATE vids SET views = views + 500 WHERE views < 1000

Please, don't even *DREAM* of using '1000' (with apostrophes). 1000 is a number. Why would you want to treat it as a string????

If you wanted to be a little less predictable, you could maybe do

UPDATE vids SET views = views + 300 + CAST( 400 * RAND() AS INT ) WHERE views < 1000

That will add a random number between 300 and 700 instead of always just 500.

Not to ask a silly question: If you are going to lie about the number of views, why show the number, at all?

Zangeel
05-25-2009, 02:16 AM
Haha, it's literally easier to update the SQL rather than take out all the "views" feilds, and featured videos is based on the amount of views, so it's easier to bump up the views to give the video site a quick jump start (not like im giving 1,000,000 views xD)

ty btw