Hi,
I am trying to create a script that checks that the posted values from a form exist in an array.
This is simple if the user has to fill out all the fields, but they don't so I need to check the $_POST array to see which variables exist, and then check each variable in the array of results from the DB.
Heres my code so far:
$SearchResult = array();
foreach ($apartmentsList as $key1 => $apartment){
foreach($_POST as $key2 => $p){
if($_POST[$key2] === $apartment[$key2] && $_POST[$key2] != "advancedSearch"){
$SearchResult[$apartment["Id"]][$key2] = $_POST[$key2];
}
}
}
$sfields = count($_POST); // FOR TESTING PURPOSE, COUNT HOW MANY POSTED VARIABLES
$results = count($SearchResult); // FOR TESTING PURPOSE, COUNT HOW MANY MATCHES THERE ARE IN ARRAY
echo "<h4>totral sFields = ". $sfields. "</h4>"; // FOR TESTING PURPOSE
echo "<pre>".print_r($_POST)."</pre>"; // FOR TESTING PURPOSE
echo "<h4>totral Results = ". $results. "</h4>"; // FOR TESTING PURPOSE
echo "<pre>".print_r($SearchResult)."</pre>"; // FOR TESTING PURPOSE
//****** THIS PART DOESN'T CHECK THAT ALL POSTED VARIBALES MATCH
if (in_array($_POST, $SearchResult)){
// PRINT MATCHES
echo "<hr><h2>Search Results</h2>";
echo "<pre>";
print_r($SearchResult);
echo "</pre>";
}
This code manages creates the array $SearchResult that holds the results where at least one posted variable matches the array. How do I ensure that ALL posted variables are in the array?
Thanks in advanced, any suggestions are really welcome