Reputation: 789
i have created custom query which i am sending via POST ajax but problem with it is that how to retrieve that data
i am sending this query = rep_id=4&filter=&filter_val=&rep_id=5&filter=&filter_val=&rep_id=6&filter=&filter_val=&from=p_employee_mst
and here is the function to fetch that query in PHP
$rep="";
foreach ($_POST["rep_id"] as $k => $v) {
$rep[]=$v;
}
print_r($rep);
i am getting following error
Invalid argument supplied for foreach()
if print_r($_POST); i am getting this
Array
(
[rep_id] => 6
[filter] =>
[filter_val] =>
[from] => p_employee_mst
)
Upvotes: 0
Views: 504
Reputation: 27295
In your example rep_id is a simple integer value. When you put more then one parameter to your variable you get the last one. in Your case its rep_id=6.
If you want an array then make an array in your request.
rep_id[]=5&rep_id[]=6
then you get as result:
array (size=2)
0 => string '5' (length=1)
1 => string '6' (length=1)
And then you can iterate over the array. Otherwise you get the following result:
rep_id=5&rep_id=6
string '6' (length=1)
Because the last value / parameter win.
Upvotes: 0
Reputation: 10967
The problem is in you're Query String
rep_id
should be represend as rep_id[]
,and you should replace it in link as URL Encoded something like : rep_id%5B%5D
Upvotes: 1