AlabamaHit Posted May 22, 2008 Share Posted May 22, 2008 I don't want to say exactly what this is for...but here it is.....its a project im working on was wondering if this would work..... $time = rand(1,5); $random = array('1' , '2' , '3' , '4' , '5'); $newtime = array('5' , '10' , '15', '20, '25'); $newtimes = str_replace($random, $newtime); $query = sprintf('UPDATE `users` SET `something` = ("%u")' , $newtime); mysql_query($query) or die (mysql_error()); What I am trying to do is make it udate the users "something" to a random number but only in the array like in example the array 5, 10, 15, 20, 25... To try to explain better....I want it to run a random nubmer 1,2,3,4,5 <<< those random numbers. Then i want it to replace those numbers (1,2,3,4,5,) with these numbers 5,10,15,20,25... Then I want it to update the users "something" with the replaced number.....^^^^^^^ EDIT: Or maybe this one? $time = rand(1,5); $newtime = str_replace(array('1' , '2' , '3' , '4' , '5'), array('5', '10', '15, '20', '25'); $query = sprintf('UPDATE `users` SET `something` = ("%u")' , $newtime); mysql_query($query) or die (mysql_error()); What I am trying to get to is a random number of only increment of 5 (between 5-25) Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted May 22, 2008 Share Posted May 22, 2008 Re: This arrray work? Not 100% sure what you mean but ... $array = array ( 0 => 5, 1 => 10, 2 => 20, 3 => 40, 4 => 80, ); $rand = mt_rand(0, 4); $value = $array[$rand]; Now, $value contains one of the value (5, 10, 20, 40 or 80) Quote Link to comment Share on other sites More sharing options...
AlabamaHit Posted May 22, 2008 Author Share Posted May 22, 2008 Re: This arrray work? THANK YOU NYNA :-D :-D :-D 8-) :lol: :mrgreen: :lol: 8-) :-D That is exactly what im looking for Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted May 23, 2008 Share Posted May 23, 2008 Re: This arrray work? Nyna to the rescue! :P Quote Link to comment 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.