I have a situation is that the query depends on user entry. If user enter toy, then query will have some OR, if user enter TV, then the query will slightly different. The simple way to do that is like below. However, when I have a lot of different products, what is the best way to do it? I want to create an array to include all products and use if condition inside the query, but if this doable or any better way? appreciate.
<?php
if ($toy){
$sql = $wpdb->get_results( $wpdb->prepare("
SELECT DISTINCT product FROM dis WHERE cat IN (%s, %s, %s)
AND (val !=%s AND mark='price')
or (val !=%s AND mark='country')
or (val !=%s AND mark='shipping')
or (val !=%s AND mark='quality')
or (val !=%s AND mark='frequency')
or (val !=%s AND mark='duration')
",$a,$b,$c,$d,$e,$f));
}
if($tv){
$sql = $wpdb->get_results( $wpdb->prepare("
SELECT DISTINCT product FROM dis WHERE cat IN (%s, %s, %s)
AND (val !=%s AND mark='price')
or (val !=%s AND mark='country')
or (val !=%s AND mark='shipping')
",$a,$b,$c,$d,$e,$f));
}
/*I have a lot*/
?>
</div>