How to Check numbers contained in a query in a field

Asked

Viewed 16 times

0

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

In this table below I list the "id_rota" 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 there within "$id_rota" , if it is contained do something

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

1 answer

2


Just use the function explode to generate a array from their string and check with in_array:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.