I am trying to create a filter function in php, that changes an SQL based on the filters that have been set, currently I have this:
if(isset($_GET['filter1']))
{
$arguements[] = "guide_type = 1";
}
if(isset($_GET['filter2']))
{
$arguements[] = "guide_type = 2";
}
if(isset($_GET['filter3']))
{
$arguements[] = "guide_type = 3";
}
if(isset($_GET['filter4']))
{
$arguements[] = "guide_type = 4";
}
if(!empty($arguements))
{
$filters = implode(' OR ',$arguements);
$get_all_guides = $DB_con->prepare('SELECT * FROM customer_stories
INNER JOIN customer_stories_guide_types
ON customer_stories.guide_type = customer_stories_guide_types.unique_id
WHERE :filters AND moderated = 1');
$get_all_guides->bindParam(':filters', $filters, PDO::PARAM_STR);
echo $get_all_guides->debugDumpParams();
The readout I get from $get_all_guides->debugDumpParams(); is SQL: [227] SELECT * FROM customer_stories INNER JOIN customer_stories_guide_types ON customer_stories.guide_type = customer_stories_guide_types.unique_id WHERE :filters AND moderated = 1 Params: 1 Key: Name: [8] :filters paramno=-1 name=[8] ":filters" is_param=1 param_type=2
I get no results when any of these filters are set and I don't know why