Hi,
I am submitting an ajax request to a php script. The values submitted in the string are:
product_category=Kitchen+Equipment&brand_name=Brabantia&brand_name=Kenwood
I put them int an array like this
$post = file_get_contents( 'php://input' );
$filterOptions = explode( '&', $post);
$filters = array();
foreach( $filterOptions as $k => $v )
{
$data = explode("=", $v);
array_push( $filters, $data );
}
That gives an an array like this:
dumping filters—
array(3) {
[0]=>
array(2) {
[0]=>
string(16) "product_category"
[1]=>
string(17) "Kitchen+Equipment"
}
[1]=>
array(2) {
[0]=>
string(10) "brand_name"
[1]=>
string(9) "Brabantia"
}
[2]=>
array(2) {
[0]=>
string(10) "brand_name"
[1]=>
string(7) "Kenwood"
}
}
Trouble is:
I need to access the values (Kenwood, Brabantia and others) using the category (brand_name) to put them in a list for use in my Db query where clause but $filters[‘brand_name’]; doesn’t get me them. I also need to get a range of items using the param $filters[‘product_category’]; with in this scenario, the category being ‘Kitchen Equipment’.
my Db query where clause is like this: (though it can be changed)
if ( in_array( "brand_name", $filters ) )
{
$where .= ' rpc.brand in ' . "('" . implode( "','" , $brands ) . "')";
}
Should I restructure the array and if so, in what way
or
am I calling the data from the array incorrectly?
Bazz