1
I’m with a php function that returns me in an html table all boards Nrplaca however I would need to put a filter in the php function to show only the boards in the table Dstpveiculo are bitruck, I would like some tips on how to do.Follows image of the database:
Php function:
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 showing 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>
Can it be in Sql no? It has to be done in php itself?
– user28595
Yes, I would like it to be in php but if you have another option accepted too.
– KevinF
Do you really need to bring the entire database table? Otherwise, just change your SQL to
SELECT * FROM GTCLogist where DsTpVeiculo ='Bitruck'
.– user28595
You can create a new method, which makes a
WHERE
in the desired field or use the method with a parameter that informs the value to be searched for.– rray
Or if you want to do it in php itself, you can put a
if($row->DsTpVeiculo == 'Bitruck')
within thewhile
, but this is waste of the query to the bank, since you can bring filtered directly from it.– user28595
I tried to change select because it was wrong: Parse error: syntax error, Unexpected 'Bitruck' (T_STRING) in DAO progDAO.php on line 14
– KevinF
You missed the quotes?
'SELECT * FROM GTCLogist where DsTpVeiculo = \'Bitruck\''
– user28595
Justo haha, I didn’t know this from Contra Barra. It helped me a lot.
– KevinF