I have the following code:
<?php
define('MYSQL_HOST', 'localhost'); define('MYSQL_USER', '***' ); define('MYSQL_PASSWORD', '***' ); define('MYSQL_DB_NAME', '***');
$cidade = isset($_POST['cidade']) ? $_POST['cidade'] : '';
$imovel = isset($_POST['imovel']) ? $_POST['imovel'] : '';
$tipo = isset($_POST['tipo']) ? $_POST['tipo'] : '';
$quartos = isset($_POST['quartos']) ? $_POST['quartos'] : '';
$banheiros = isset($_POST['banheiros']) ? $_POST['banheiros'] : '';
$sql = "SELECT * FROM im_casa WHERE cidade LIKE '$cidade' AND quartos LIKE '$quartos' AND banheiros LIKE '$banheiros' AND imovel LIKE '$imovel' AND tipo LIKE '$tipo' ORDER by id DESC";
$PDO = new PDO('mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD); $PDO->exec("set names utf8");
// cria o Prepared Statement e o executa
$stmt = $PDO->prepare($sql);
$stmt->bindValue(':cidade', '%' . $cidade . '%');
$stmt->bindValue(':imovel', '%' . $imovel . '%');
$stmt->bindValue(':tipo', '%' . $tipo . '%');
$stmt->bindValue(':quartos', '%' . $quartos . '%');
$stmt->bindValue(':banheiros', '%' . $banheiros . '%');
$stmt->execute();
// cria um array com os resultados
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?php
include 'includes/header.php';
include 'includes/nav1.php';
include 'includes/nav2.php';
?>
<body>
<h1 style="text-align: center; padding:5%;">Resultados de sua busca:</h1>
<div class="container" style="margin-bottom: 3%;">
<div class="row">
<?php if (count($products) > 0): ?>
<?php foreach ($products as $product): ?>
<style>
#box {
padding: 5%;
text-align: center;
-moz-box-shadow: -1px 1px 3px #CCC;
-webkit-box-shadow: -1px 1px 3px #CCC;
box-shadow: -1px 1px 3px #CCC;
margin-bottom: 10%;
}
</style>
<div class="col-md-3">
<div id="box">
<?php
$id = $product['id'];
$consulta = $PDO->query( "SELECT * FROM im_casa WHERE id = '$id';" );
while ( $linha = $consulta->fetch( PDO::FETCH_ASSOC ) ) {
$pasta = "painel/galeria/casa/principal/$linha[codigointerno]";
$imagens = glob( "$pasta/{*.jpg,*.JPG,*.png,*.PNG}", GLOB_BRACE );
foreach ( $imagens as $img ) {
?>
<img src="<?php echo $img ?>" class="img-responsive img-rounded"> <?php } } ?>
<h2><?php echo $product['cidade'] ?></h2>
<p>Valor: R$ <?php echo number_format($product['valor'], 2, ',', '.') ?></p>
<p><?php echo $product['titulo'] ?></p>
<a href="imovel.php?id=<?php echo "$id";?>" class="btn btn-warning">Ver mais!</a>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<center><p>Nenhum resultado encontrado! Confira os termos de sua busca.</p></center>
<?php endif; ?>
</div>
</div>
<?php
include 'includes/footer.php';
include 'includes/links.php';
?>
As the images are inside a folder, and need to use another foreach, when listed, only the image of a bank field appears.
In summary, I can not understand the logic to solve this question.