Hello, I have a problem with this function when deleting, I search for what will be compared, and I put two delete conditions, because I need it to delete two tables in one condition, and if there is nothing in the other table, delete only one, in my simplicity I used a if
but the search when it does not find any results in the table, it does not execute the rest.
Can you help me?
function deleta_pessoa_pg($conexao,$id){
$id_valor = "SELECT viva.* from viagens_valor as viva where viva.id_pessoa = '$id'";
$resultado = mysqli_query($conexao, $id_valor) or die(mysqli_error($conexao));
$listaitem = mysqli_fetch_assoc($resultado) or die(mysqli_error($conexao));
//echo $listaitem['id_pessoa'];
if (!$listaitem['id_pessoa']) {
//echo 'fala';
$query2 = "DELETE FROM viagens WHERE id = '$id'";
return mysqli_query($conexao, $query2) or die(mysqli_error($conexao));
}else{
//echo 'oi';
$query = "DELETE v.*, vv.* FROM viagens as v left JOIN viagens_valor as vv ON vv.id_pessoa = v.id WHERE v.id = '$id'";
return mysqli_query($conexao, $query) or die(mysqli_error($conexao));
}
}