Hello. I'm sending some data over AJAX to a PHP file. It's about filter options. Anyway, I am sending it like this:
filter[0][data][type] string
filter[0][data][value] automobiles
filter[0][field] product
filter[1][data][type] numeric
filter[1][data][value] 6000
filter[1][field] price
This above is taken from FireBug console. Then, in PHP:
$filter = $_POST['filter'.$i];
if (is_array($filter)) {
for ($i=0;$i<count($filter);$i++){
switch($filter[$i]['data']['type']){
case 'string' :
// I'm doing my select from database based on that and so on
So, the translation of this would be: "Get me all the records from database that are: hmm, let's check the filters... I'm getting the first filter type witch is "string" witch needs to be applied to the mysql column named "product"...So I'm searching for the value of "automobiles" there...But I'm not finished yet, the second filter refers to a numeric filter for the column "price" from database. so I'm taking its value and add it to the query. So I'll end up selecting all the automobiles that have a price greater than 6000.
So far so good. The problem is that my way of getting data have changed and I can't send my data in this format no more. The new format is an URL witch looks like this:
filter[0][field]=prodct&filter[0][data][type]=string&filter[0][data][value]=automobiles&filter[1][field]=price&filter[1][data][type]=numeric&filter[1][data][value]=6000
I can do an explode on this one by the "&" and end up with an array...I can do a lot... The problem is that I don't know how to adjust my query building script to work with that kind of received data..So that I can do a "switch($filter[$i]['data']['type']){" again...
Any ideas for modifying the code ?
Thank you!