Jump to content

mySQL random


squiggerz

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/54224-mysql-random/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/54224-mysql-random/#findComment-268268
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/54224-mysql-random/#findComment-268281
Share on other sites

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.