You are only going to get the last one. You are repeatedly overwriting sub2 and sub3 in the query string. You can use the same key names over and over again. You need to POST an array, not use GET.
How about telling us about the real problem instead of asking about your attempted solution to it. What is the high level overview of what you have going on.
I need to query the database to find a match for each of the posted form fields.
so using the query string it would be;
WHERE subject=2 AND product=73
WHERE subject=2 AND product=76
WHERE subject=2 AND product=79
WHERE subject=3 AND product=73
WHERE subject=2 AND product=74
I dont know why the query string would be formatted that way, it seems rather cumbersome. that beign said, I recommend the following:
$or = $where ='';
foreach($_POST as $key => $val) {
if (substr($key, 0,3) !='sub') { continue;}
$data[]= substr($key, 3);
$data[]= substr($val, 3);
$where. ="$or( sub = ? AND pro = ?)";
if (!$or && $where) { $or = ' OR ' ; }
}
$sql = "SELECT * FROM table WHERE '. $where
// USE PDO-> exec($data) to query the DB
Hope that helps. also DO USE PDO, never trust user input.