Problems adding fetchAll results to an array

Asked

Viewed 39 times

1

private $resultado;

public function buscaTodos($query){
    $stmt = $this->conn->prepare($query);
    $stmt->execute();
    $this->resultado = $stmt->fetchAll(PDO::FETCH_OBJ);
}

public function getAllResults(){
    $resultados = $this->resultado;

    foreach($resultados AS $key=>$resultado){

        $arr[] = array(
            "DDD 1" =>  $resultado->ddd1,
            "Tel 1"   => $resultado->tel1,              
            "Agendamento" =>  $resultado->data_agendamento,
            "concluir" =>  "<a class='link' href=\"page1.php?id=" . $resultado->id . "\"><img src=\"images/check.png\" title=\"Concluir Processo\"></a>"

        );
    }

    return $arr;
}

HTML page:

$queryMailling = "SELECT * FROM $table_name WHERE status='4'";
$dadosMailling->buscaTodos($queryMailling);

$dados = $dadosMailling->getAllResults();


    foreach($dados AS $key=>$front){
        echo "<tr>";
        foreach($front AS $resultado) {
            echo "<td>" . $resultado . "</td>";
        }
        echo "</tr>";
    }

has how to make a loop using only one foreach? there is another method to add values within an array without being like this: $arr[]?

  • makes the function searchTodos($query) return fetchAll and mounts only one foreach on the html page

No answers

Browser other questions tagged

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