php function filter pdo

1

I have a php function that returns me in a table all html NrPlaca but I would need a filter in the php function to show in the table only the DsTpVeiculo > are bitruck, I would like some tips on how to do it. Next image of the database:

Function php:

class ProgDAO{

  private $conn;

  public function __construct($connection) {
      $this->conn = $connection;
  }

  public function ListaTodos(){
          $results = array();
          $stmt = $this->conn->prepare(
              'SELECT * FROM GTCLogist'
          );
          $stmt->execute();
          if($stmt) {
              while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
                  $prog = new Prog();
                  $prog->setplaca($row->NrPlaca);
                  $prog->setmot(stripslashes($row->DsMotorista));
                  $results[] = $prog;
              }
          }
      return $results;
  }

}

Table that shows the data:

    <table  border="1" width="30%">
            <tr>
                <th>BITRUCK</th>
                <th>Motorista</th>
                <th>Data Saída</th>
                <th>Origem</th>
                <th>Destino</th>
                <th>Prev. Cheg. Dest</th>
                <th>Carga/Manifesto</th>
                <th>Adiantamento Fincanceiro</th>
                <th>Agendas</th>
                <th>Malote</th>
                <th>Obs</th>
            </tr>

            <?php
                    foreach ($controller->listarEmail() as $objProg) {
                        ?>
                            <tr>
                                <td><?php echo $objProg->getplaca(); ?></td>
                                <td><?php echo $objProg->getmot(); ?></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                <?php
                    }
                ?>

        </table>
    
asked by anonymous 07.01.2016 / 12:47

1 answer

2

You can create a new method to list the cards by type, the difference is that this method receives a parameter, which will be used in the WHERE

public function ListaPorTipo($tipo){
    $results = array();
    $stmt = $this->conn->prepare('SELECT * FROM GTCLogist WHERE DsTpVeiculo = ?');
    $stmt->execute(array($tipo));
    if($stmt) {
        while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
        $prog = new Prog();
        $prog->setplaca($row->NrPlaca);
        $prog->setmot(stripslashes($row->DsMotorista));
        $results[] = $prog;
    }else{
        print_r($stmt->errorInfo());
    }
    return $results;
}

And the call goes something like:

<?php
$prog = new ProgDAO ($conexao);
$itens = $prog->listaPorTipo('bitruck');
    
07.01.2016 / 13:14