Jump to content

I need help with generating random string


afaaro

Recommended Posts

I have got this one but it's only working with small letters and numbers, how can i make both lower case and upper case and numbers as well. this is the query am using right now

dbquery("UPDATE ".CATEGORY." SET category_url=CONCAT(LOWER(SUBSTRING((CONV(SUBSTRING(RAND(), 3), 10, 36)), 1, ))");

I would suggest creating the code in PHP. But the below will work. It's ugly, but will work.

 

 

$query = "UPDATE " . CATEGORY . "
          SET category_url = CONCAT(
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1),
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1),
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1),
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1),
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1),
              SUBSTR('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', FLOOR(1+RAND()*62), 1)
          )";

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.