Comparison of mysql records with php array

2

I need to compare the id contained within a php array, with those of a field in a mysql table. The idea is NOT to show the id (of the php array) in the mysql query response.

$consulta="SELECT * FROM permisos_pedidos WHERE id_cliente = '$id_us' AND id = '$trat'";
$ejecutar_consulta = $conexion->query($consulta);
$perm = array();
while ($registro = $ejecutar_consulta->fetch_assoc())
{
    $perm[] = $registro["etapas"];
}

$ perm is my array that contains the ids of the users. Now, what I need, is that in another query, do not show me the id of the users that are in $ perm. What the array shows me (which is correct):

array(2) { [0]=> string(1) "9" [1]=> string(2) "10" }

Where 9 and 10 are the ids that I should not show in the next query. Any ideas on how to make this comparison? As always, thank you very much everyone.

    
asked by maha1982 02.06.2018 в 04:23
source

1 answer

0

I imagine that what you want is to remove permissions from the table, the permissions of users different from those that you have requested in the first query, if this is the simplest way it would be the following:

"$consulta = select * FROM permisos_pedidos WHERE id_cliente not in (". implode(',', $perm ). ")"

I hope that the client_id is the discriminant you want to use, likewise, the idea would be that, use a not in to look for those that are not within a set, in this case the list of ids of the variable $ perm.

I hope this helps you.

Greetings

    
answered by 21.06.2018 в 17:06