How to make the result be published in the right place?

0

I'm using require on my page, so the result is being printed after the footer, someone would know how to solve it, follow the code:

<?php

require ("principal.php");

$servidor = "localhost";
$usuario = "root";
$senha = "root";
$tabela = "guianortecapixaba";

$conexao = new mysqli($servidor, $usuario, $senha, $tabela);

if ($conexao->connect_error) {
    die("Erro: " . $conexao->connect_error);
}

$busca = $_POST['palavra'];
$cidade = $_POST ['cidade'];

$sql = "SELECT * FROM empresa WHERE nome LIKE '%$busca%' AND cidade = '$cidade'";
$resultados = $conexao->query($sql);


if ($resultados->num_rows > 0) {
    while($linha = mysqli_fetch_array($resultados)) {
        print("<strong>Nome: </strong>" . $linha['nome'] . "</br>");
        print ("<strong>Endereço: </strong>" . $linha['endereco']."</br>");
        if( isset($_POST['cidade']) && $_POST['cidade'] === 'sao-gabriel-da-palha' ) {
            $fromPerson = 'São Gabriel da Palha';
            echo "<strong>Cidade: </strong>".$fromPerson."</br>";
        }
        print ("<strong>Telefone: </strong>" . $linha['telefone']."</br>");
        echo "<strong>email: </strong>". $linha['email']."</br>";
        echo "<hr>";
    }
} else {
    echo "Nenhum resultado para a sua busca.";
}

$conexao->close();

?>
    
asked by anonymous 10.08.2017 / 18:17

1 answer

1

So let's, create a new file with the content, removing the contents of the current file:

Let's hypothetically call the return.php file (name should be changed to your need)

$servidor = "localhost";
$usuario = "root";
$senha = "root";
$tabela = "guianortecapixaba";

$conexao = new mysqli($servidor, $usuario, $senha, $tabela);

if ($conexao->connect_error) {
    die("Erro: " . $conexao->connect_error);
}

$busca = $_POST['palavra'];
$cidade = $_POST ['cidade'];

$sql = "SELECT * FROM empresa WHERE nome LIKE '%$busca%' AND cidade = '$cidade'";
$resultados = $conexao->query($sql);


if ($resultados->num_rows > 0) {
    while($linha = mysqli_fetch_array($resultados)) {
        print("<strong>Nome: </strong>" . $linha['nome'] . "</br>");
        print ("<strong>Endereço: </strong>" . $linha['endereco']."</br>");
        if( isset($_POST['cidade']) && $_POST['cidade'] === 'sao-gabriel-da-palha' ) {
            $fromPerson = 'São Gabriel da Palha';
            echo "<strong>Cidade: </strong>".$fromPerson."</br>";
        }
        print ("<strong>Telefone: </strong>" . $linha['telefone']."</br>");
        echo "<strong>email: </strong>". $linha['email']."</br>";
        echo "<hr>";
    }
} else {
    echo "Nenhum resultado para a sua busca.";
}

After this inside main.php exactly at the point where you should return this data you will enter:

<?php
    require ("retorno.php");

Remembering that return.php is the name we gave this new file, I think this solves your problem.

    
10.08.2017 / 18:54