squiggerz Posted June 5, 2007 Share Posted June 5, 2007 I have a script that pulls code from a field in a row in mySQL db randomly, is there a way to have several instances of this pulling in the same script, pulling randomly from the remaining rows without repeating? I guess what I'm needing is a function to lock the row once it has been used in the script so that it doesnt use the same row again, then unlock the rows once the script is complete. Is this even possible? Quote Link to comment https://forums.phpfreaks.com/topic/54224-mysql-random/ Share on other sites More sharing options...
zq29 Posted June 5, 2007 Share Posted June 5, 2007 Create a field in the database called 'lock' with an ENUM('0','1'), select only rows where `lock`='0' and set `lock`='1' on selected rows, then at the end of the script just set `lock`='0' again. Or, select all your rows at once, in a random order with "ORDER BY RAND() LIMIT 5", store them in an array, and loop through the array as and when you need one of the rows. Quote Link to comment https://forums.phpfreaks.com/topic/54224-mysql-random/#findComment-268268 Share on other sites More sharing options...
siwelis Posted June 5, 2007 Share Posted June 5, 2007 Maybe just have the query keep repeating and if $result2 = $result1, then repeat query until otherwise. or after getting $result1 then $result2 = mysql_query(SELECT * FROM table WHERE identification NOT CONTAINS $result1) modify that how you may, but currently i think that will pull everything except $result1 NOT CONTAINS $result1 OR $result2 ... not sure how many times you can use OR over again... Quote Link to comment https://forums.phpfreaks.com/topic/54224-mysql-random/#findComment-268281 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.