0

I have a Tinder like script with images of males and females. On every page the script shows one person and the user can go to the next person. In my situation I'm using:

ORDER BY rand(".preg_replace('/\D/', '', Cookie::get('random')).")

So ordering by a random number I put in the cookie.

I have a lot of males and few females. How can I influence the RAND() function to show more females?

Nathaniel
  • 237
  • 2
  • 6

1 Answers1

3

First start with just doing order by rand(), and remove the stuff between (). That will also give you a random order.

Second, if you want as many men as women, or some kind of ratio, you need to UNION two queries. One query where you get random men, and another query where you get random women.

edit:

Another way to go about it is do do:

order by (if(gender='f',rand()/5,rand())

when 1:5 is the ratio woman/man.

nl-x
  • 11,762
  • 7
  • 33
  • 61