jcsickz Posted February 5, 2008 Share Posted February 5, 2008 This is a randomization script... basically $altboom is a random text variable which will be entered into a mysql record; it needs to be run on every record in my database. As it stands, this code runs the randomization script one time. I need the random text string line to be run once for each. How can I tell PHP to do this? //define the random text string $randomtext = ($str1 . " " . $str2 . " " . $str3 . " " . $str4 . " " . $str5 . " " . $str6 . " " . $str7); //insert the random text string into the record mysql_query("UPDATE table SET field = '$altboom' WHERE '*' = '*'"); Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/ Share on other sites More sharing options...
ratcateme Posted February 5, 2008 Share Posted February 5, 2008 To do this just remove your where clause that should work. another point i would like to make is that in mysql wild card is not * it is % Scott. Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-458539 Share on other sites More sharing options...
jcsickz Posted February 6, 2008 Author Share Posted February 6, 2008 well, it works, but the same as it did before. I need the $altboom variable to be "defined" once for each record. As it stands (and with the changes recommended) it puts the same exact random text in each record. How can I make the randomization script be run seperately for each record in the query? I know this may be confusing, but any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-459322 Share on other sites More sharing options...
ratcateme Posted February 6, 2008 Share Posted February 6, 2008 i don't no what kind of random string you want but you could use something like $altboom=md5(time()); or for a more random string $altboom=md5(time()*rand(0,99999); if you only want numbers just remove the md5 part and if you wanted something smaller than 32 use sub str eg $altboom=substr($altboom,0,15); for a 15 chr long string Scott. Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-459380 Share on other sites More sharing options...
Zane Posted February 6, 2008 Share Posted February 6, 2008 $query = mysql_query("SELECT * FROM table"); while($row = mysql_fetch_array($query)) { $rand = rand(1, 9999); $update = mysql_query("UPDATE table set `field` = $rand WHERE `id` = {$row['id']}"); } Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-459387 Share on other sites More sharing options...
jcsickz Posted February 6, 2008 Author Share Posted February 6, 2008 I think we are on the wrong track. Let me explain the script a bit more fully: //this block of code defines $str1... there is a similar block of code to define $str2, $str3, etc srand((float) microtime() * 10000000); $input = array("fun", "happy", "silly", "wacky", "cool", "lucky", "cool", "cute", "attractive", "great", "unreal", "sweet", "nice"); $rand_keys = array_rand($input, 2); $str1 = $input[$rand_keys[0]]; //define the random text string. This needs to happen individually for every MySQL insert $randomtext = ($str1 . " " . $str2 . " " . $str3 . " " . $str4 . " " . $str5 . " " . $str6 . " " . $str7); //insert the random text string into the record. Needs some kind of clause to get a new $randomtext for every insert mysql_query("UPDATE table SET field = '$randomtext' WHERE '*' = '*'"); Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-459941 Share on other sites More sharing options...
Zane Posted February 7, 2008 Share Posted February 7, 2008 I think we are on the wrong track. Let me explain the script a bit more fully: well $query = mysql_query("SELECT * FROM table"); while($row = mysql_fetch_array($query)) { $i = 0; //srand((float) microtime() * 10000000); $input = array("fun", "happy", "silly", "wacky", "cool", "lucky", "cool", "cute", "attractive", "great", "unreal", "sweet", "nice"); //$rand_keys = array_rand($input, 2); $randomtext = implode(" ", $input); //$str1 = $input[$rand_keys[0]]; //$update = mysql_query("UPDATE table set `field` = $rand WHERE `id` = {$row['id']}"); //$rand = rand(1, 9999); $update = mysql_query("UPDATE table set `field` = '{$andomtext}' WHERE `id` = {$row['id']}"); } Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-460371 Share on other sites More sharing options...
jcsickz Posted February 8, 2008 Author Share Posted February 8, 2008 Thanks for the help, but that code doesn't work. I wish I knew why, but it doesn't insert anything into the field. Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-461379 Share on other sites More sharing options...
jcsickz Posted February 16, 2008 Author Share Posted February 16, 2008 desperation bump. Please take another look at this Quote Link to comment https://forums.phpfreaks.com/topic/89513-running-a-randomization-script-on-all-of-my-mysql-records/#findComment-468447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.