You can add to this table the column TINY INT (1)
, of for example name usado
and at search time do search limited to one with the condition used 0
,
For example:
SELECT column
FROM table
WHERE usado = 0
ORDER BY RAND()
LIMIT 1
in this query I get a random record limited to one that has not yet been used,
After picking up this record you update the same to usado = 1
For example:
UPDATE table SET usado=1 WHERE id=aqui_seria_o_id_recebido_na_busca_anterior
When running the first query leave a condition in case the search does not return anything, it runs an update to update the whole table and so run the select
again.
Example:
UPDATE table SET usado=0
In case I’m simply updating the entire table to the status usado = 0
.
All these changes would be on the server side, so you wouldn’t need to change html or javascript
, but of course that’s just my idea. I hope I’ve helped.
Get it, search for "Fisher-Yates" right here on the site for the algorithm. Basically you store an array in the browser (cookies, localstorage etc). If you do it on the PHP side, with Session or similar mechanism is better. Just "shuffle" the numbers and an array, and redo the draw only after using all (do not need to touch the DB for this). It would be important for you to [Edit] your post and put the code you are using as the basis, the structure of the DB or array used, etc., to serve as the basis for the answers. - PHP-side function ready http://php.net/manual/en/function.shuffle.php
– Bacco
@Bacco saw a post about you more I found complicated rsrsrs because in my case I just want one result at a time and somehow I believe q some time the function can be slow due to the number of records, vo after the one analyzed calmly, thanks for the help.
– Patrique Alves
500 numbers is a very low value. Just vc do an array and $drawn = shuffle( $original ). Ai will take one by one of the array until it is over (and only draw again when the array is over). Fooling around with eight lines of code does the whole thing. Remembering that just draw the numbers, the rest takes the DB according to the current number only when using - if (Count($drawn)==0) { generate and shuffle }; removes the 1st of the array and uses. Save back in session; - basically this solves everything
– Bacco
I understood, but the trend is this number grow, anyway gave me to understand your logic and I will do some tests here too, thanks.
– Patrique Alves