I have a question or concern. I have to query the database and check if the field is empty, insert a number. I am using a do_while loop and the idea is that the query is repeated as many times as necessary until the field is empty, this is the code I have at the moment:
public function consultar($id)
{
$resultado = $this->Model_login->traerPrueba($id);
do {
$comprobar = $this->Model_login->traerPrueba($resultado->id_izquierda);
$resultado = $comprobar->id;
echo " " . $resultado . "";
} while (!empty($resultado->id_izquierda));
echo "si termina si funciona acá ".$resultado->id;
}
and this is the model that queries me:
public function traerPrueba($id)
{
$sql = "SELECT id, id_papa_pago, id_izquierda ,nombre,apellido1
FROM master_usuarios
WHERE id= ?";
$query = $this->db->query($sql,[$id]);
return $query->row();
}
The error I have is that it asks me only once. It brings me the first echo and by the way it breaks the cycle. But according to my database, the loop has to break after the third query that there is an empty field.
Edited question: This is the query that the database brings me if I give the $id a value of 7
the field is not empty, so it would have to be repeated but with the value that appears in id_izquiera which is 10701
but instead of continuing with the loop, it terminates and does not continue querying until it finds left_id = (null) or empty
for the model you located it should be something like this:
As you can see I am using a foreach and the empty
Thanks to ArcanisGK507's comment, it made me realize something, and for the moment I just wanted the query. I had the order wrong and I was consulting again and then if I printed the message, it was first to print the message and then if I replaced the variable so that it would repeat the cycle and that's how it was