I am trying to get this working based on the answers found in this SO question: How to search by key=>value in a multidimensional array in PHP - but I am having no luck.
I am querying the database. I need to take the results and place all the ones that have 'type' = $type into a new array to use that new array for displaying info.
The Search Function:
function search($array, $key, $value){
$results = array();
search_r($array, $key, $value, $results);
return $results;
}
function search_r($array, $key, $value, &$results){
if (!is_array($array)) {
return;
}
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
search_r($subarray, $key, $value, $results);
}
}
The Code:
$getTypes = mysqli_query($link, "SELECT * FROM Type WHERE section = ".$selectValue." ORDER BY `order`");
$getCategories = mysqli_query($link, "SELECT * FROM Category WHERE section = ".$selectValue." ORDER BY `order`");
$getdbvalues = mysqli_query($link, "SELECT * FROM `Data` WHERE section = ".$selectValue." AND `date` = ".$datecomp);
$dbvalues = mysqli_fetch_assoc($getdbvalues);
while($type = mysqli_fetch_assoc($getTypes)){
$typeid = $type['id'];
$getdbdata = search($dbvalues, 'type', $typeid);
while($category1 = mysqli_fetch_assoc($getCategories)){
// DISPLAY DATA FROM $getdbdata
}
}