I'm making standard profile pictures for 5000 users, and right now i need to insert a referance in the 'users' table. I don't want all the users to have the same standard profile picture, so i'm trying to update the 'user_profile_image' row with one of the strings listen in the query below.
UPDATE users 
SET user_profile_image = rand('adrian.jpg', 'bendix.jpg', 
hr_skaeg.jpg', `'jeppe.jpg')
The query doesn't seem to work.
Is this way too simple?
Any help is much appreciated!
Kind regards, Mathias
RAND() returns a number between 0 and 1; if you multiply it by the number of pictures you have and take the FLOOR(), you can switch on the result with ELT:
UPDATE users SET user_profile_image =
 ELT(1 + FLOOR(RAND()*4), 'adrian.jpg', 'bendix.jpg', 'hr_skaeg.jpg', 'jeppe.jpg');
                        You need to read the manual. RAND() doesn't do what you seem to think it does.
Try this instead:
UPDATE users
SET user_profile_image = 
    CASE FLOOR(RAND() * 4) 
    WHEN 0 THEN 'adrian.jpg.img' 
    WHEN 1 THEN 'bendix.jpg' 
    WHEN 2 THEN 'hr_skaeg.jpg' 
    WHEN 3 THEN 'jeppe.jpg' 
    END
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With