Web Analytics Made Easy -
StatCounter Concating random value into existing field value - CodingForum

Announcement

Collapse
No announcement yet.

Concating random value into existing field value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Concating random value into existing field value

    Hi, on my test site i have been using the same email for a bunch of users just to test some pagination so it did not matter if they had the same email.

    Now that i want to test other features i need to fix that, i dont want to update manually and all i want to do is run a query that adds a random number to the front of each current email value so they are all unique.

    I thought i had it with this... (did not know mysql could do this)

    Code:
    UPDATE `user_data` SET `user_email` = concat(FLOOR(RAND()*(10-5+1)+5)) WHERE `user_email` = "[email protected]" AND `user_id` > 0
    it ran sucessfully but it did not concat, it just replaced the value with a random number.

    where did i mess up in the query that it did not just add the rand number to the value that was there?

    UPDATE: got it.....

    Code:
    UPDATE `wss_user_data` SET `user_email` = concat(FLOOR(RAND()*(10-5+1)+5), `user_email`) WHERE `user_email` = "[email protected]" AND `user_id` > 0
    probably should have stuck with the first rand equasion, the second one gave me some negative results such as -2 and such.
    Last edited by durangod; Jul 3, 2020, 05:28 AM.
    If a php file only has php code within it you do not need to use the closing php tag
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

  • #2
    I think your query is right but you have syntax quote error. I have tried your query and applied the following was returned the desired output which you want :

    Code:
    UPDATE wss_user_data SET user_email = concat(FLOOR(RAND()*(10-5+1)+5), user_email) WHERE user_email = '[email protected]' AND  user_id > 0;
    I think you should try by adding the seed value of RAND() function, like RAND(9) :

    Code:
    UPDATE wss_user_data SET user_email = concat(FLOOR(RAND()*(10-5+1)+5), user_email) WHERE user_email = '[email protected]' AND user_id > 0;
    ASP.Net Software Development

    Comment

    Working...
    X