How to check numbers contained in a query in a field

0

How to check if an id is contained within a range of ids within a field in the database

In this table below I list the "routable id" it returns me IDs separated by comma 16,17,18,19 .....

$numero = $_GET["numero"];
$bd = new MySQLiConnection();   
$sql3 = $bd->prepare( "SELECT * FROM pax where id_rfid = ?  "  ) or exit( 
$mysqli->error );
$sql3->bind_param('s', $id_rfid); // Coloca o valor de $data no lugar da 
primeira interrogação (?) 
$sql3->execute();
$resultcar = $sql3->get_result(); 
while( $row = $resultcar->fetch_assoc() )
{                               
$id_rota1 = $row['id_rota'];//   16,17,18,19,20

}

I need to check if a number is within "$ id_rota", if it is contained do something

example if number 17 is inside $ rotate_id echo "ok";

    
asked by anonymous 08.06.2018 / 20:25

1 answer

2

Just use the explode function to generate an array from your string and check with in_array :

if (in_array($numero, explode(',', $row['id_rota']))) {
    // Número está na sequência de ids
}
    
08.06.2018 / 20:44