Help with logic in SELECT

1

I have a "matchmaking" script (as if it were a game). He checks every 3 seconds a table to see if there are 10 players who are not playing. But I also need to check if these 10 players are one of them.

The select is like this

$busca_db_qtd = mysqli_query($conexao, "SELECT ativo, gamemode, playing, id_user FROM users_buscando WHERE ativo = '1' and gamemode = '$gamemode' and playing = '0' and reservados = '0' LIMIT 10");

I need to check if these 10 players, one of them has my id. How can I do this without having to do a while in php and use a lot of processing (I think it uses ne)?

    
asked by anonymous 19.07.2018 / 17:05

1 answer

0

Try to put the players ids you find while running the macthmaking script in an array $ array players.

array_push($array, $jogador->id);

Then just check the array for duplicates.

function has_dupes($array) {
$dupe_array = array();
foreach ($array as $val) {
    if (++$dupe_array[$val] > 1) {
        return true;
    }
}
return false;
}

Function "function has_dupes" found in Link to source by @Mike Sherov

    
19.07.2018 / 18:31