Generate button in DIV?

1

I have a DIV call ( meusBotoes ) and I would like every loop of while to generate a button within the DIV with the value of the variable $nome and with the onclick it calls the function displayAlerta ().

My while

<?php
$host = "";
$bd = "";
$usr = "";
$psw = "";

$conn = new mysqli($host, $usr, $psw, $bd);
if ($conn->connect_error) 
{
die("A conexão falhou, consulte o suporte: " . $conn->connect_error);
} 
$sql = "SELECT id, nome, tipo, imagem FROM produtos";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{

while($row = $result->fetch_assoc())
{
$id = $row['id'];
$nome = $row['nome'];
$tipo = $row['tipo'];
$imagem = $row['imagem']; 
}

}
?>

Is there an easy way to do this in% with% of same, without% with%?

    
asked by anonymous 07.10.2017 / 17:23

1 answer

1

Basically that's it, playing while within div :

connect_query.php

<?php
$host = "";
$bd = "";
$usr = "";
$psw = "";

$conn = new mysqli($host, $usr, $psw, $bd);
if($conn->connect_error) 
{    die("A conexão falhou, consulte o suporte: " . $conn->connect_error);
} 
$sql = "SELECT id, nome, tipo, imagem FROM produtos";
$result = $conn->query($sql);  
?>

pag_btn.php

<?php include 'connect_query.php';?>
<div id="meusBotoes ">
    <?php     
    while($row = $result->fetch_assoc())
    {    $id = $row['id'];
         $nome = $row['nome'];
         $tipo = $row['tipo'];
         $imagem = $row['imagem']; 
         echo"<button id=".$nome." onclick='exibirAlerta()'>".$nome."</button>";
    }
    ?>
</div>
    
07.10.2017 / 18:20