I need to search the database using the DtBase column, for example: on day 26 I populated the table with several information, on day 28 I want to see what I did on day 26. I want an input date or another method that it is more feasible for me to select the date and to return the records of the bank of this day that I have selected. If the selected date does not exist in DtBase it does not show anything, if it exists it displays all records from the database table inside the html table I have below in the code.
Database column:
TablewhereIwantafieldabovetoselectthedate,andinthetablereturntherecordsofthedayselectedinthefield:
<?php$controller=newComando($conn);?><formmethod="POST" action="../controller/progPrecontrole.php">
<div class="large-12 columns">
<div class="TableCSS" >
<table>
<tr>
<td>ST</td>
<td>BITRUCK</td>
<td>Motorista</td>
<td>Data Saída</td>
<td>Origem</td>
<td>Destino</td>
<td>Previsão chegada</td>
<td>Carga/Manifesto</td>
<td>Adiantamento Fincanceiro</td>
<td>Agendas</td>
<td>Malotes</td>
<td colspan="2">Observação</td>
</tr>
<?php
foreach ($controller->ListaPorTipoB() as $objProg) {
?>
<tr>
<td>
<?php
echo ($controller->RetornarCarctere($objProg->getst()));
?>
</td>
<td><?php echo $objProg->getplaca(); ?></td>
<td><?php echo $objProg->getmot(); ?></td>
<td><?php echo $objProg->getsaida(); ?></td>
<td><?php echo $objProg->getorig(); ?></td>
<td><?php echo $objProg->getdest(); ?></td>
<td><?php echo $objProg->getprev(); ?></td>
<td><?php echo $objProg->getcarga(); ?></td>
<td><?php echo $objProg->getadfin(); ?></td>
<td><?php echo $objProg->getagen(); ?></td>
<td><?php echo $objProg->getmal(); ?></td>
<td class="t1" ><div><?php echo $objProg->getobs(); ?></div></td>
<td><a href="edita.php?id=<?php echo $objProg->getid();?>"><p>Alterar</p></a></td>
</tr>
<?php
}
?>
</table>
</div>
</form>
Functions I have so far:
class ProgDAO{
private $conn;
public function __construct($connection) {
$this->conn = $connection;
}
public function ListaPorTipoB($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->setid($row->ID);
$prog->setst($row->DsStatus);
$prog->setplaca($row->NrPlaca);
$prog->setmot(stripslashes($row->DsMotorista));
$prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
$prog->setorig($row->DsOrigem);
$prog->setdest($row->DsDestino);
$prog->setprev(date('d/m/Y', strtotime($row->DtPrevChegDest)));
$prog->setcarga($row->DsCarga);
$prog->setadfin($row->DsAdFin);
$prog->setagen($row->DsAgendas);
$prog->setmal($row->DsMalote);
$prog->setobs($row->DsObservacao);
$results[] = $prog;
}
}
return $results;
}
public function ListaPorTipoT($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->setid($row->ID);
$prog->setst($row->DsStatus);
$prog->setplaca($row->NrPlaca);
$prog->setmot(stripslashes($row->DsMotorista));
$prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
$prog->setorig($row->DsOrigem);
$prog->setdest($row->DsDestino);
$prog->setprev(date('d/m/Y', strtotime($row->DtPrevChegDest)));
$prog->setcarga($row->DsCarga);
$prog->setadfin($row->DsAdFin);
$prog->setagen($row->DsAgendas);
$prog->setmal($row->DsMalote);
$prog->setobs($row->DsObservacao);
$results[] = $prog;
}
}
return $results;
}
public function ListaPorTipoC($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->setid($row->ID);
$prog->setst($row->DsStatus);
$prog->setcarreta($row->CdCarreta);
$prog->setplaca($row->NrPlaca);
$prog->setmot(stripslashes($row->DsMotorista));
$prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
$prog->setorig($row->DsOrigem);
$prog->setdest($row->DsDestino);
$prog->setprev(date('d/m/Y', strtotime($row->DtPrevChegDest)));
$prog->setcarga($row->DsCarga);
$prog->setadfin($row->DsAdFin);
$prog->setagen($row->DsAgendas);
$prog->setmal($row->DsMalote);
$prog->setobs($row->DsObservacao);
$results[] = $prog;
}
}
return $results;
}
public function editar(Prog $prog){
$this->conn->beginTransaction();
try {
$stmt = $this->conn->prepare(
'UPDATE GTCLogist SET DsStatus = :DsStatus, DsMotorista = :DsMotorista, DtSaida = :DtSaida,
DsOrigem = :DsOrigem, DsDestino = :DsDestino, DtPrevChegDest = :DtPrevChegDest, DsCarga = :DsCarga,
DsAdFin = :DsAdFin, DsAgendas = :DsAgendas, DsMalote = :DsMalote, DsObservacao = :DsObservacao,
CdCarreta = :CdCarreta
WHERE ID = :ID'
);
$stmt->bindValue(':ID', $prog->getid(), PDO::PARAM_INT);
$stmt->bindValue(':DsStatus', $prog->getst(), PDO::PARAM_INT);
$stmt->bindValue(':DsMotorista', $prog->getmot(), PDO::PARAM_STR);
$stmt->bindValue(':DtSaida', $prog->getsaida(), PDO::PARAM_INT);
$stmt->bindValue(':DsOrigem', $prog->getorig(), PDO::PARAM_STR);
$stmt->bindValue(':DsDestino', $prog->getdest(), PDO::PARAM_STR);
$stmt->bindValue(':DtPrevChegDest', $prog->getprev(), PDO::PARAM_INT);
$stmt->bindValue(':DsCarga', $prog->getcarga(), PDO::PARAM_STR);
$stmt->bindValue(':DsAdFin', $prog->getadfin(), PDO::PARAM_INT);
$stmt->bindValue(':DsAgendas', $prog->getagen(), PDO::PARAM_STR);
$stmt->bindValue(':DsMalote', $prog->getmal(), PDO::PARAM_STR);
$stmt->bindValue(':DsObservacao', $prog->getobs(), PDO::PARAM_STR);
$stmt->bindValue(':CdCarreta', $prog->getcarreta(), PDO::PARAM_INT);
$stmt->execute();
$this->conn->commit();
}
catch(Exception $e) {
$this->conn->rollback();
}
}
public function listar($id){
$prog = new Prog();
$stmt = $this->conn->prepare(
'SELECT * FROM GTCLogist WHERE ID = :ID'
);
$stmt->bindValue(':ID', $id, PDO::PARAM_INT);
$stmt->execute();
if($stmt) {
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$prog->setid($row->ID);
$prog->setst($row->DsStatus);
$prog->setcarreta($row->CdCarreta);
$prog->setplaca(stripslashes($row->NrPlaca));
$prog->setmot($row->DsMotorista);
$prog->setsaida(date('d/m/Y', strtotime($row->DtSaida)));
$prog->setorig($row->DsOrigem);
$prog->setdest($row->DsDestino);
$prog->setprev(date('d/m/Y', strtotime($row->DtPrevChegDest)));
$prog->setcarga($row->DsCarga);
$prog->setadfin($row->DsAdFin);
$prog->setagen($row->DsAgendas);
$prog->setmal($row->DsMalote);
$prog->setobs($row->DsObservacao);
}
}
return $prog;
}
public function ListaData(){
$results = array();
$stmt = $this->conn->prepare('SELECT * FROM GTCLogist');
$stmt->execute();
if($stmt) {
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
if($row->ID == '1'){
$prog = new Prog();
$prog->setid($row->ID);
$prog->setdata(date('d/m/Y', strtotime($row->DtBase)));
$results[] = $prog;
}
}
}
return $results;
}
}
Control:
<?php
class Comando{
private $conn;
public function __construct($connec) {
$this->conn = $connec;
}
public function ListaPorTipoB(){
$dao = new ProgDAO($this->conn);
return $dao -> ListaPorTipoB('Bitruck');
}
public function ListaPorTipoT(){
$dao = new ProgDAO($this->conn);
return $dao -> ListaPorTipoT('Truck');
}
public function ListaPorTipoC(){
$dao = new ProgDAO($this->conn);
return $dao -> ListaPorTipoC('Cavalo Truck');
}
public function ListaData(){
$dao = new ProgDAO($this->conn);
return $dao -> ListaData();
}
public function editar(Prog $objProg){
$dao = new ProgDAO($this->conn);
return $dao -> editar($objProg);
}
public function listar($id){
$dao = new ProgDAO($this->conn);
return $dao -> listar($id);
}
public function RetornarCarctere($x){
$dao = new ProgDAO($this->conn);
return $dao -> RetornarCarctere($x);
}
}
?>