-1
Hello, I have a problem in this function when deleting, I do a search of what will be compared, and put two delete condition, because I need it to delete in one condition two tables, and if there is nothing in the other table, delete only one, in my simplicity I used one if
but the search when it does not find any results in the table, it does not perform the rest.
I wonder if you can 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));
}
}
First of all, the "viva*" of the first select is missing the point. There are other code problems, but to comment on them, you’d need to understand exactly what you want to do. If your IF depends on quantities, you have to parse num_rows (or affected_rows in other cases that generate changes), and not if fetch brought the first
– Bacco
Hello, the question of the code 'point' I have already corrected, I will explain from the beginning of the process, come on: I register a person who will travel in a table, and then register the amounts that she has been paying, but to delete this person I also need to erase the amounts paid by this person. then I’ll have to delete in two tables at once, so far so good, but when I need to delete only one this delete command for the two tables, not delete only one, and for that I created the query and the IF, and compare the value of the query with the $ID that comes in the 'Function'.
– Junior Venancio