Skip to content

Instantly share code, notes, and snippets.

@celsowm
Created June 30, 2019 20:33
Show Gist options
  • Save celsowm/da6b7ca9daa5059e624c9e594a6d7f04 to your computer and use it in GitHub Desktop.
Save celsowm/da6b7ca9daa5059e624c9e594a6d7f04 to your computer and use it in GitHub Desktop.
<?php
include 'conexao.php';
$filtro = ["preco_minimo" => "1.98"];
$edicoes = [1,2,10];
$edicoes = array_combine(
array_map(function($i){ return ':id'.$i; }, array_keys($edicoes)),
$edicoes
);
$in_placeholders = implode(',', array_keys($edicoes));
$sql = "SELECT * FROM livro WHERE preco >= :preco_minimo AND edicao IN ($in_placeholders)";
$statement = $pdo->prepare($sql);
$statement->execute(array_merge($filtro,$edicoes));
foreach($statement as $livro){
echo $livro['titulo']."</br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment