0

Tenho uma função que retorna os resultados,que vão preencher minha tabela. Eu quero que, quando não tiver resultado,apareça uma mensagem,que não existem informações a serem exibidas, atualmente, ma minha tabela, quando não tem registro,aparece somente o cabeçalho da tabela.

     <?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>";
                }



        }
?>
2
  • Você não colocou o código da função multas que exibe a primeira tabela. 19/06/2018 às 12:38
  • Bom dia amigo! A função multa é idêntica a de notificações, só muda o "AND MUL.MULCHE = 'N'",não coloquei pra não ficar muito extenso,mas basicamente fazem a mesma coisa.
    – Thiagão
    19/06/2018 às 12:42

1 Resposta 1

0

Eu trabalho montando a tabela direto na function e dou um echo na variável. Vê se te ajuda dessa forma.

$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;

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .