Reputation: 485
I'm looking to make a progress bar that advances between two dates that have been set stored on my MySQL.
i saw some ways with javascript but didn't worked to me... i have low experience with sql and i will apreciate some way to catch date from my DB and use on this while to build a table with progressbar
My PHP code with connection MySQL + While
<?php
include 'conexao/conexao.php';
$sql = "SELECT * FROM trabalho_v2";
$busca = mysqli_query($conexao, $sql);
while ($dados = mysqli_fetch_array($busca))
{
$trab_id = $dados['trabalho_id'];
$cliente = $dados['Nome_cliente'];
$tema = $dados['titulo_trabalho'];
$recebido = $dados['trabalho_recebido'];
$entrega = $dados['data_entregar'];
$tipo = $dados['tipo_trabalho'];
?>
<!-- // TABLE -->
<tr>
<td>
<?php echo $trab_id ?>
</td>
<td>
<?php echo $cliente ?>
</td>
<td>
<?php echo $tema ?>
</td>
<td>
<div class="progress-wrapper">
<div class="progress-info">
<div class="progress-percentage">
<span>60%</span>
</div>
</div>
<div class="progress">
<div class="progress-bar bg-primary" id="progressbar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%; height:40px;"></div>
</div>
</div>
Date 01: <?php echo $recebido ?><br>
Date 02: <?php echo $entrega ?>
</td>
<td>
<?php echo $tipo ?>
</td>
<td>
<a href="editarTrabalho.php?id=<?php echo $trab_id ?>" role=button class="btn btn-primary">Editar</a>
</td>
</tr>
<?php
} ?>
- What data will determine the percentage?
Start: DATE 1 = $recebido
End: DATA 2 = $entrega
Upvotes: 0
Views: 264
Reputation: 485
i found this solution with pure php without javascript:
<?php
// ESSA PARTE É PARA O CONTADOR DE DIAS
$data_entrega = $dados['data_entregar'];
$data_recebe = date("Y-m-d");
// transforma a data do formato BR para o formato americano, ANO-MES-DIA
$data_entrega = implode('-', array_reverse(explode('/', $data_entrega)));
$data_recebe = implode('-', array_reverse(explode('/', $data_recebe)));
// converte as datas para o formato timestamp
$d1 = strtotime($data_entrega);
$d2 = strtotime($data_recebe);
// verifica a diferença em segundos entre as duas datas e divide pelo número de segundos que um dia possui
$dataFinal = ($d1 - $d2) /86400;
// caso a data 2 seja maior que a data 1, finaliza pq entende que passou da data
if($dataFinal < 0)
$dataFinal = "fim";
?>
Upvotes: 2