jeudi 26 février 2015

MySQL random record with RAND() and caluses

I have a database where I want to get a random draw from my entries. I can do that perfectly with:



$query = "SELECT * FROM mytable ORDER BY RAND()


The problem is that the database contains the entry order of horse jumpers in a competition and no jumper can jump consecutively. I have the following setup:


|jumper | horse | id|


| Pedro | gfs | 1 |


| Gustavo | psg | 2 |


| Breno | sdwed | 3 |


| bruno | sdsd | 4 |


| Carlos | powkd | 5 |


| Andrea | linda | 6 |


| Gustavo | handara | 7 |


I have to prevent the jumper Gustavo from being drawn consecutively to jump since he would have to change horses very fast. In fact, if he is drawn, he can only be drawn again after 3 other competitors. Would appreciate any ideas on how to do that.





Aucun commentaire:

Enregistrer un commentaire