Validate table row contents

Asked

Viewed 131 times

0

I have a function that returns the results, which will fill my table. I want that when there is no result, a message appears,.

     <?php 
     //Pagina principal
    session_start(); // Inicia a sessão
    include_once("func/functions.php"); // Chama o arquivo de funções padrão.
    include_once("func/f_descontos.php"); // Chama o arquivo de funções do específicas.


    if ($_SESSION['userPermission'] <> 14) // Valida o grau de permissão para mostrar botão de navegação entre motoristas
       $show="hidden";

    if (is_null($_SESSION['userName'])) // Valida se existe usuário logado
        header('location:./index.php');

    // Cria as variáveis para identifação de período atual e registro do usuário logado.

    $motorista = isset($_POST['motorista']) ? $_POST['motorista'] : $_SESSION['userCodMot'];
    $foto = (isset($_SESSION['userPhoto'])) ? 'fotos/'.$_SESSION['userPhoto'] : 'fotos/YAPONYRA_FOTO.jpg';

    ?>
    <!DOCTYPE html>
     <html>
        <head>
            <meta http-equiv=Content-Type content="text/html; charset=utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title> Descontos </title>
            <link rel="stylesheet" href="css/bootstrap.min.css">
            <script type="text/javascript"  src="js/jquery.min.js"></script>
            <script type="text/javascript"  src="js/bootstrap.min.js"></script>
            <script type="text/javascript"  src="js/comandos.js"></script>
            <link rel="stylesheet" href="css/descontos.css">
            <link rel="stylesheet" href="css/padrao.css">
            <link rel="stylesheet" href="css/mobile/retrato.css" media="screen and (orientation: portrait)">
            <link rel="stylesheet" href="css/mobile/paisagem.css" media="screen and (orientation: landscape)">
        </head>
        <body onmousemove="acao();"> <!-- Função acao() faz verificação de ociosidade no painel, após determinado tempo ele fecha. -->
            <div class="container-fluid">
                <div class="head">
                    <?php include_once("menu.php"); ?>
                </div >
            </div>  
            <div class="container-fluid">
                <div class="table-responsive">
                    <h4>Multas</h4>
                    <table class="table table-bordered table-striped table-sm">
                        <thead class="thead-dark">
                            <tr>
                                <th>Lançamento</th>
                                <th>Data da Multa</th>
                                <th>Situação</th>
                                <th>Valor</th>
                                <th>Local</th>
                                <th>Observação</th>
                                <th>Limite Recurso</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php echo multas($motorista)?>
                        </tbody>
                    </table>
                </div>
                    <div class="table-responsive">
                    <h4>Notificações</h4>
                    <table class="table table-bordered table-striped table-sm">
                        <thead class="thead-dark">
                            <tr>
                                <th>Lançamento</th>
                                <th>Data da Notificação</th>
                                <th>Situação</th>
                                <th>Valor</th>
                                <th>Local</th>
                                <th>Observação</th>
                                <th>Limite Recurso</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php echo notificacoes($motorista)?>
                        </tbody>
                    </table>
                </div>
            </div>  
        </body>
    </html>

<?php
    //Função que retorna os registros
    function notificacoes($codMot)
        {
                $conn_datapar = connect();
                $sql = "SELECT MUL.CODIGO,MUL.NUMAUT,
                        case MUL.SITUAC
                            WHEN 1 THEN 'DEFERIDO'
                            WHEN 2 THEN 'INDEFERIDO'
                        WHEN 3 THEN 'AGUARDANDO RECURSO'
                        ELSE
                            'AGUARDANDO BOLETO'
                        END SITUACAO,
                        MUL.DATREF,MUL.LOCMUL,MUL.ORGEMI,MUL.NUMGUI,MUL.CODENQ,INF.DESCRI,MUL.LIMREC,(MUL.VLRMUL-MUL.DESCAN)VALOR,MUL.MULCHE
                        FROM RODMUL MUL
                        INNER JOIN TMP_INFRACAO INF ON MUL.CODENQ = INF.CODIGO
                        WHERE  MUL.CODMOT = '$codMot'
                        AND INF.CODIGO <> '683-12'
                        AND MUL.MULCHE = 'N'
                        ORDER BY MUL.DATREF";
                $stmt = sqlsrv_query($conn_datapar, $sql);
                if( $stmt == false)
                header('location:index.php?msg="Falha');

                while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
                {
                    $lancamento = $row["CODIGO"];
                    $auto = $row["NUMAUT"];
                    $situacao = $row["SITUACAO"];
                    $data = $row["DATREF"]->format('d-m-Y H:i');
                    $local = $row["LOCMUL"];
                    $orgao = $row["ORGEMI"];
                    $guia = $row["NUMGUI"];
                    $codEnq = $row["CODENQ"];
                    $obs = $row["DESCRI"];
                    $valor = $row["VALOR"];
                    $datRecurso = $row["LIMREC"]->format('d-m-Y H:i');
                    echo "<tr>";
                                echo "<td>".$lancamento."</td>";
                                echo "<td>".$data."</td>";
                                echo "<td>".$situacao."</td>";
                                echo "<td>R$".number_format($valor,2,',','.')."</td>";
                                echo "<td>".$local."</td>";
                                echo "<td  width='40%'>".$obs."</td>";
                                echo "<td>".$datRecurso."</td>";
                    echo "</tr>";
                }



        }
?>
  • You did not put the code of the fines function that displays the first table.

  • Good morning, my friend! The fine function is identical to notifications, only changes the "AND MUL.MULCHE = 'N'",I did not put to not be too extensive, but basically do the same thing.

1 answer

0

I work by assembling the table directly in Function and give an echo in the variable. See if it helps you that way.

$html        = "<br/><br/><table width='100%' border='0'>";

            if(count($ocorrencias) > 0){
                $html .="<tr><th>Detalhe</th><th>Código</th><th>Cliente</th><th>Motivo</th><th>Responsável</th><th>Data</th></tr>";
                foreach($ocorrencias as $ocorrencia){
                    $html .="<tr><td><a href='#' target='_blank'>Detalhe</a></td>"
                            . "<td>".$ocorrencia['ite_ich_codigo']."</td>"
                            . "<td>".$ocorrencia['ict_nome']."</td>"
                            . "<td>".$ocorrencia['imo_titulo']."</td>"
                            . "<td>".$ocorrencia['ifu_nome']."</td>"
                            . "<td>".$ocorrencia['ioc_data_ini']."</td></tr>";

                }
            }else{

                $html .="<tr><td><center>Nenhum resultado encontrado</center></td></tr>";

            }

            $html       .= "</table>"; 

            echo $html;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.