随机结果显示PHP

I am working on a site that matches up users, just like any dating website. Except, I would like the users matches to randomly be displayed 1 at a time. Like they just click next until the come across a result they like. I know how to query the results in a list format but what sort of code would I need to use to randomly display their match's profiles, randomly chosen (based on the match score), one at a time? I am using PHP. Thanks! If you even tell me what to look up that would be great!

I suppose you have a "complex" mysql request.. You can just add an ORDER BY RAND(), and process that list using ajax for instance.

SELECT ...
FROM yourtable
WHERE .... search conditions ...
ORDER BY rand()
LIMIT 1

Is the easiest, but most likely least efficient method of doing this. Re run the query each time they click next and you'll get a random entry of the matches. Note that this won't prevent duplicates from showing up, which is very likely if there's very few matches.

You SHOULD NOT use mysql's ORDER BY RAND() clause because it's slow, it's better to act like this:

  1. select max(id) from profiles
  2. select profile.* from profiles where profile.id = mt_rand(0, MAX_ID)

will be much more better for performance