Skip to main content
adicionou 1604 caracteres ao conteúdo
Fonte Link
                        <?php
                    if($tabela == 'controle_insumos') {
                        $sql =  mysql_query("SELECT controle_insumos.*, prod01.* FROM controle_insumos INNER JOIN prod01 ON controle_insumos.rwc = prod01.procod LIMIT 200 ");
                    while ($result = mysql_fetch_array($sql) )
                    {
                    echo "<tr>";
                    echo "<td>".$result['rwc']."</td>";
                    echo "<td>".$result['prodes']."</td>";
                    echo "<td>".$result['quantidade']."</td>";
                    echo "<td>".$result['pround']."</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['data_compra']));
                    echo "</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['fabricacao']));
                    echo "</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['validade']));
                    echo "</td>";
                     $data2 = new DateTime($result['validade']);
                     $data1 = new DateTime();
                     $intervalo = $data1->diff($data2);
                        
                        
                        if ($intervalo<0) {
                            echo "<td style='background: red;'>";   
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo<30)  {
                            echo "<td style='background: green;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo>90)  {
                            echo "<td style='background: blue;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                        }
                    echo "</tr>";
                        }
                    }
                    else                        
                    $sql =  mysql_query("SELECT $res_codigo as rwc, $res_nome as descricao, $res_un as unidade FROM $tabela order by RAND() LIMIT 200 ");
                if($sql== 0)
                        $sql =  mysql_query("SELECT $res_codigo as rwc, $res_nome as descricao, $res_un as unidade FROM $tabela order by RAND()");
                    while ($result = mysql_fetch_array($sql) )
                    {
                    echo "<tr>";
                    echo "<td>".$result['rwc']."</td>";
                    echo "<td>".$result['descricao']."</td>";
                    echo "<td>".$result['unidade']."</td>";
                    echo "<td><button class='btn btn-lg btn-primary btn-block' type='submit'>Comprar</button></td>";
                    echo "</tr>";
                    }
            ?>
            
          $data2 = new DateTime($result['validade']);
          $data1 = new DateTime();
          $intervalo = $data1->diff($data2);    
                        
                        if ($intervalo<0) {
                            echo "<td style='background: red;'>";   
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo<30)  {
                            echo "<td style='background: green;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo>90)  {
                            echo "<td style='background: blue;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                        }
                    echo "</tr>";
                        }
                        <?php
                    if($tabela == 'controle_insumos') {
                        $sql =  mysql_query("SELECT controle_insumos.*, prod01.* FROM controle_insumos INNER JOIN prod01 ON controle_insumos.rwc = prod01.procod LIMIT 200 ");
                    while ($result = mysql_fetch_array($sql) )
                    {
                    echo "<tr>";
                    echo "<td>".$result['rwc']."</td>";
                    echo "<td>".$result['prodes']."</td>";
                    echo "<td>".$result['quantidade']."</td>";
                    echo "<td>".$result['pround']."</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['data_compra']));
                    echo "</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['fabricacao']));
                    echo "</td>";
                    echo "<td>";
                    echo date('d/m/Y', strtotime($result['validade']));
                    echo "</td>";
                     $data2 = new DateTime($result['validade']);
                     $data1 = new DateTime();
                     $intervalo = $data1->diff($data2);
                        
                        
                        if ($intervalo<0) {
                            echo "<td style='background: red;'>";   
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo<30)  {
                            echo "<td style='background: green;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo>90)  {
                            echo "<td style='background: blue;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                        }
                    echo "</tr>";
                        }
                    }
                    else                        
                    $sql =  mysql_query("SELECT $res_codigo as rwc, $res_nome as descricao, $res_un as unidade FROM $tabela order by RAND() LIMIT 200 ");
                if($sql== 0)
                        $sql =  mysql_query("SELECT $res_codigo as rwc, $res_nome as descricao, $res_un as unidade FROM $tabela order by RAND()");
                    while ($result = mysql_fetch_array($sql) )
                    {
                    echo "<tr>";
                    echo "<td>".$result['rwc']."</td>";
                    echo "<td>".$result['descricao']."</td>";
                    echo "<td>".$result['unidade']."</td>";
                    echo "<td><button class='btn btn-lg btn-primary btn-block' type='submit'>Comprar</button></td>";
                    echo "</tr>";
                    }
            ?>
            
Fonte Link

Trabalhar com datas vindas do MySQL/PHP

Dentro de um select no banco, busco a data de validade do produto. Preciso que seja calculada mudando um status na resposta tipo 'a vencer', 'critico' e vencido'. Estou tentando fazer desta forma abaixo, mas estou meio enferrujado.

          $data2 = new DateTime($result['validade']);
          $data1 = new DateTime();
          $intervalo = $data1->diff($data2);    
                        
                        if ($intervalo<0) {
                            echo "<td style='background: red;'>";   
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo<30)  {
                            echo "<td style='background: green;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                            }
                        elseif ($intervalo>90)  {
                            echo "<td style='background: blue;'>";
                            echo $intervalo->format('%R%');
                            echo "</td>";
                        }
                    echo "</tr>";
                        }