Return data from my table formatting in html

0

I have a function inside my class to list data; Here is the code below:

public function listadados(){

       try{
           //retornar um array
           $sql = "SELECT * FROM web_cadcli";
           $lista = $this->con->conectar()->prepare($sql);
           $lista->execute();
           $retDados = array ( $lista-> fetchAll(PDO::FETCH_ASSOC));
           print_r($retDados);
       }catch(PDOException $erro_2){
           echo 'erro'.$erro_2->getMessage();       
       }
}

I want to put the return that is below. inside an html

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [idcad_cliente] => 1
                    [nm_cliente] => Rodrigo Zanetti
                    [email_cliente] => [email protected]
                    [senha_cliente] => 7ik3ikelek
                    [id_identpess] => 1
                    [img] => 
                )

            [1] => Array
                (
                    [idcad_cliente] => 2
                    [nm_cliente] => Rodrigo Zanetti
                    [email_cliente] => [email protected]
                    [senha_cliente] => k3ik3ik3ikkejeh
                    [id_identpess] => 1
                    [img] => 
                )

            [2] => Array
                (
                    [idcad_cliente] => 3
                    [nm_cliente] => Adriana Silva Souto
                    [email_cliente] => [email protected]
                    [senha_cliente] => k3ikeikeikeieçeoel
                    [id_identpess] => 1
                    [img] => 
                )

This screen below is my template, where I want to return the formatted values. name underneath NAME: email below EMAIL, as a table.

listados (); ? >
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <tr class="active">
                    <th>Nome</th>
                    <th>E-mail</th>
                    <th>Editar</th>
                   <th>Deletar</th>
                </tr>
            </thead>
            <tbody>
            </table>

    
asked by anonymous 05.06.2017 / 01:41

1 answer

1

Maybe this is the solution:

List () method

 public function listadados(){

       try{
           //retornar um array
           $sql = "SELECT * FROM web_cadcli";
           $lista = $this->con->conectar()->prepare($sql);
           $lista->execute();
           $retDados = $lista-> fetchAll(PDO::FETCH_ASSOC);

           return $retDados;

       }catch(PDOException $erro_2){
           echo 'erro'.$erro_2->getMessage();       
       }
}

So the array with the records will be returned and can be used as follows.

<?php
  $objeto = new NomeDaClasse;
  $clientes = NomeDaClasse->listadados();
?>

<table class="table table-striped table-bordered table-hover">
            <thead>
                <tr class="active">
                    <th>Nome</th>
                    <th>E-mail</th>
                    <th>Editar</th>
                   <th>Deletar</th>
                </tr>
            </thead>
            <tbody>
               <?php foreach($clientes as $cliente) : ?>
                   <tr>
                     <td><?=$cliente['nm_cliente']?></td>
                     <td><?=$cliente['email_cliente']?></td>
                     <td><a href="?id_cliente=<?=$cliente['idcad_cliente']?>&action=editar">Editar</a></td>
                     <td><a href="?id_cliente=<?=$cliente['idcad_cliente']?>&action=deletar">Deletar</a></td>
                   </tr>
               <?php endforeach; ?>
            </tbody>
            </table>

Return data can be passed to a variable and passed through a foreach loop.

This part of Edit and Delete placed the parameters assuming $ _GET would be used since you did not say anything about that part.

    
05.06.2017 / 03:37