Printar result in DIV

Asked

Viewed 45 times

1

How I can put the results in every different div. Need to display the image searching from a directory and a link that directs to a particular page.

<?php
$servidor = "localhost";
$usuario = "admin";
$senha = "";
$dbname = "uaicheibd";
//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);

$pesquisar = $_POST['pesquisar'];
$result_clientes = "SELECT * FROM pesquisaclientes WHERE palavras_chave LIKE '%$pesquisar%' LIMIT 5";
$resultado_clientes = mysqli_query($conn, $result_clientes);


    echo '<div class="resultados">';
while($rows_clientes = mysqli_fetch_array($resultado_clientes)){
    echo "Cliente: ".$rows_clientes['nome']."<br>";
    echo "Bairro: ".$rows_clientes['bairro']."<br>";
    echo "Categoria: ".$rows_clientes['categoria']."<br>";
    echo "Subcategoria: ".$rows_clientes['subcategoria']."<br>";
    echo "Link: ".$rows_clientes['link_cliente']."<br>";
    echo "Logo: ".$rows_clientes['logo']."<br>";
}
    echo '</div>';
?>
  • It’s not enough to do the echo of the div inside her while? If not, then I don’t understand the doubt.

1 answer

1


The link you put in a tag <a> where the attribute href (and the text, if you like) will be the information coming from the bank:

echo "Link: <a href='".$rows_clientes['link_cliente']."'>".$rows_clientes['link_cliente']."</a><br>";

In the case of the image, tag <img> where the attribute src will be the image path + the information coming from the bank:

echo "Logo: <img src='caminho_do_diretorio/".$rows_clientes['logo']."'><br>";

Where in caminho_do_diretorio you will put the folder path, which can be a subfolder, a previous folder etc. It will depend on the folder structure or the way you will find the folder where the image is.

For example, if you are in a folder imagens in the same directory of the page, will make:

echo "Logo: <img src='imagens/".$rows_clientes['logo']."'><br>";

Or you can search globally, regardless of where the page is, using ./:

echo "Logo: <img src='./site/imagens/".$rows_clientes['logo']."'><br>";

In the above case, it will fetch the image inside the folder site/imagens from the root folder.

  • Perfect Sam. Thank you very much.

Browser other questions tagged

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