I'm starting PDO and I need to make a query, but I do not do it, I do not know if the problem is with the variables I use in the query or I'm declaring something wrong in my code.
This code is the one of my variables:
foreach ($_POST['ciudades'] as $value) {
if ($current != $num_countries-1){
$where2 = $where2 . $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'" . $subclas . "'" . ')' . ' ' . 'OR' . ' '. $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'unica'" . ')' . ' ' . 'OR' . ' ';
}else{
$where3 = $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'" . $subclas . "'" . ')' . ' ' . 'OR' . ' '. $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'unica'" . ')';
}$current++;
}
And the code of the query is as follows:
$q = $pdo->prepare('SELECT * FROM :tipoTarifa2 WHERE :where2 :where3');
$q ->execute(array("tipoTarifa2"=>$tipoTarifa2,"where2"=>$where2,"where3"=>$where3));
$result = $q->fetchAll();
foreach ($result as $data) {
echo $data["Id"];
}