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

Asked

Viewed 354 times

0

Greetings,

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

I managed to make the 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>
  <script src="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;
}
  • I understand that you want to show this result on the page somewhere specific, but where is this place? No iframe? Another thing is the TAG used in the question, you marked it as java, but I don’t see any java in your code, it wouldn’t be Javascript?

  • Thank you so much for your attention. The place would be in TD q has id= painel_requisicoes and java was wrong msm.

  • Welcome Rodrigo Maniezzo, if any answer solves your problem be sure to mark it as accepted. See how in https://i.stack.Imgur.com/jx7Ts.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079 If you would like to tour the site visit https://answall.com/tour

2 answers

0


It’s quite simple, you put the database query on the page (I decided to put in the head) and within the td that you want to show the lines, puts the result (This result can be better formatted, put as you posted), follows 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>
      <script src="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>
  • Gave it right, just do it and save the page as php and not as html. Thank you very much

  • Oops, I forgot to pay attention to the extension of the hehe file. In need, we are there.

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 ?>');

Browser other questions tagged

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