How to print the result of a SELECT (php / sql) in a specific place in the HTML page?

0

Greetings,

I have a database with a table of purchase requisitions. In my html there is a panel where the number of purchase requisitions registered will be displayed.

I was able to SELECT right and print the results on a blank page.

But the goal is to print the result inside the request panel that already exists in an HTML page.

How to do this?

<!DOCTYPE html>
<html lang="pt-br">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="_css/estilo.css"/>
    <title>MPparts - seu mercado de peças</title>
  </head>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="jquery.big-slide.js"></script>
  <script>
    $(document).ready(function() {
      $('.menu-link').bigSlide();
    });
  </script>
<body>

<div id="interface">
    <section id="menulateral">

    <header id="cabecalhomenu">
        <figure class="foto-usuario" >
            <img src="_imagens/fotousuario.png">
            <figcaption>
            </figcaption>
        </figure>
    </header>

    <nav id="menu" class="panel" role="navigation">
        <ul>
            <li><a href="incluir_requisicao.php">Nova requisição</a></li>
            <li><a href="teste1.html">The Ballad of El Goodo</a></li>
            <li><a href="#">Thirteen</a></li>
            <li><a href="#">September Gurls</a></li>
            <li><a href="logout.php">logout</a></li>
        </ul>
    </nav>
    </section>

    <section id="painelusuario">
        <header id="cabecalhopainel">
            <table id="tabelaindicadores" cellpadding="0px" cellspacing="50px">
                <tr>
                    <td class="indicadorpainel" id="painel_requisicoes">Requisições<br>x </td>
                    <td class="indicadorpainel" id="painel_cotacoes">Cotações</td>
                    <td class="indicadorpainel" id="painel_transito">Em Transito </td>
                    <td class="indicadorpainel" id="painel_recebimento">Recebimento</td>
                </tr>
            </table>
        </header>

        <div id="areadetrabalho">

            <header id="cabecalhoareadetrabalho">

                teste


            </header>

            <IFRAME name= areadetrabalhoframe src="novarequisicao.html" frameBorder=0 width=100% height=100% scrolling=auto></IFRAME>


        </div>

    </section>




</div>

<?php
include ('conexao.php');

$listarequisicoes=mysqli_query($conexao,"select id_requisicao, 
count(id_requisicao) from tb_requisicoes group by id_requisicao having 
count(id_requisicao)>0 ") or die("erro");//lista todas as requisicoes cadastradas no banco de dados
$linhas= mysqli_num_rows($listarequisicoes);//conta requisicoes

if ($linhas==''){

    echo 'nenhum registro';
}
else{
    echo $linhas;
}
    
asked by anonymous 05.12.2018 / 15:19

2 answers

0

It's very simple, you put the query to the database on the page (I decided to put it in head ) and inside the td you want to show the lines, put the result (This result can be better formatted, as you posted), follow the code:

<!DOCTYPE html>
<html lang="pt-br">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="_css/estilo.css"/>
    <title>MPparts - seu mercado de peças</title>

    <?php
        include ('conexao.php');

        $listarequisicoes=mysqli_query($conexao,"select id_requisicao, 
        count(id_requisicao) from tb_requisicoes group by id_requisicao having 
        count(id_requisicao)>0 ") or die("erro");//lista todas as requisicoes cadastradas no banco de dados
        $linhas= mysqli_num_rows($listarequisicoes);//conta requisicoes
    ?>

      </head>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="jquery.big-slide.js"></script>
      <script>
        $(document).ready(function() {
          $('.menu-link').bigSlide();
        });
      </script>
    <body>

    <div id="interface">
        <section id="menulateral">

        <header id="cabecalhomenu">
            <figure class="foto-usuario" >
                <img src="_imagens/fotousuario.png">
                <figcaption>
                </figcaption>
            </figure>
        </header>

        <nav id="menu" class="panel" role="navigation">
            <ul>
                <li><a href="incluir_requisicao.php">Nova requisição</a></li>
                <li><a href="teste1.html">The Ballad of El Goodo</a></li>
                <li><a href="#">Thirteen</a></li>
                <li><a href="#">September Gurls</a></li>
                <li><a href="logout.php">logout</a></li>
            </ul>
        </nav>
        </section>

        <section id="painelusuario">
            <header id="cabecalhopainel">
                <table id="tabelaindicadores" cellpadding="0px" cellspacing="50px">
                    <tr>
                        <td class="indicadorpainel" id="painel_requisicoes">
                            Requisições<br>
                            <?php
                                if ($linhas==''){
                                    echo 'nenhum registro';
                                }
                                else{
                                    echo $linhas;
                                }
                            ?>
                        </td>
                        <td class="indicadorpainel" id="painel_cotacoes">Cotações</td>
                        <td class="indicadorpainel" id="painel_transito">Em Transito </td>
                        <td class="indicadorpainel" id="painel_recebimento">Recebimento</td>
                    </tr>
                </table>
            </header>

            <div id="areadetrabalho">

                <header id="cabecalhoareadetrabalho">

                    teste


                </header>

                <IFRAME name= areadetrabalhoframe src="novarequisicao.html" frameBorder=0 width=100% height=100% scrolling=auto></IFRAME>

            </div>

        </section>

    </div>
    
05.12.2018 / 15:58
0

In PHP

if ($linhas==''){

    $texto = 'Requisições<br>nenhum registro';
}
else{

     $texto = 'Requisições<br>'.$linhas;
}

HTML

  

Within JavaScript include this line

$("#painel_requisicoes").html('<?php echo $texto ?>');
    
05.12.2018 / 16:50