SELECT * FROM `companys`
INNER JOIN `countrys` USING(`country_id`)
INNER JOIN `prices` ON `companys`.`company_id` = `prices`.`company_id`
INNER JOIN `service_description` USING(`description_id`)
WHERE
`RU` = "1" AND
`companys`.`security` = "YES" AND
"?" > ANY(
SELECT `price` FROM `prices`
INNER JOIN `service_description` USING ( `description_id` )
WHERE `service_name` = "?"
)
array(2) { [0]=> string(4) "1000" [1]=> string(9) "dedic_max" }
class GetCompanys {
private $_query = 'SELECT * FROM `companys` INNER JOIN `countrys` USING(`country_id`) INNER JOIN `prices` ON `companys`.`company_id` = `prices`.`company_id` INNER JOIN `service_description` USING(`description_id`)';
private $_predicate_min = ' "?" < ANY(
SELECT `price` FROM `prices`
INNER JOIN `service_description` USING ( `description_id` )
WHERE `service_name` = "?"
)';
private $_predicate_max = ' "?" > ANY(
SELECT `price` FROM `prices`
INNER JOIN `service_description` USING ( `description_id` )
WHERE `service_name` = "?"
)';
private $_data = array();
private $_pdo;
function __construct($pdo) {
$this->_pdo = $pdo;
}
public function get() {
$this->create_query();
return $this->execute();
}
private function execute() {
$companys = $this->_pdo->prepare($this->_query);
echo $this->_query."<br>";
var_dump($this->_data);
if(isset($this->_data))
{
$companys->execute($this->_data);
}
else
$companys->execute();
foreach ($companys as $key => $value) {
var_dump($value);
echo "<br>";
}
$companys->debugDumpParams();
return $companys;
}
//
// CREATE QUERY
//
private function create_query() {
foreach($_POST as $key => $value)
{
if (strlen($this->_query) == 194) {
$this->_query .= ' WHERE ';
} else {
$this->_query .= ' AND ';
}
$this->set_filter($key, $value);
}
}
private function set_filter($key, $value) {
switch($key) {
case 'country':
$this->_query .= ' `'.$value.'` = "1"';
break;
case 'security':
$this->_query .= ' `companys`.`security` = "'.$value.'"';
break;
default:
if ($this->is_min($key)) {
$this->_query .= $this->_predicate_min;
} else {
$this->_query .= $this->_predicate_max;
}
$this->_data[] = $value;
$this->_data[] = $key;
break;
}
}
private function is_min($key) {
$key = strtolower(substr($key, -3));
if ($key == 'min') {
return true;
} else {
return false;
}
}
}