Итак, я возвращаю массив массивов, возвращаемых из запроса MySQLi, поскольку вы можете видеть, что он извлекает отдельные категории из моей базы данных слоев, а затем возвращает каждый слой, связанный с этой категорией.
Результаты возвращают только некоторые результаты, а не все, когда код, использующий print_r, возвращает все слои.
Куда я иду не так?
https://api.adameastwood.com/v1/TEST/logger.php -> результаты print_r и цикла foreach
$conn = new mysqli($sqlParams['host'], $sqlParams['username'],
$sqlParams['password'], $sqlParams['database']);
$Query = "SELECT DISTINCT `Category` FROM `layers` WHERE `enabled` = 1
ORDER BY `Category` ASC";
$menuCategories = [];
if ($result = $conn->query($Query))
{
while ($categoryRow = $result->fetch_row()){
foreach($categoryRow as $key => $value)
{
$layers = $conn->query("SELECT * FROM `layers` WHERE enabled = 1 AND Category = '$value' ORDER BY LayerName ASC");
while ($layerDetails = $layers->fetch_array()){
$menuItems = array([
'LCategory' => $layerDetails['Category'],
'LayerCode' => $layerDetails['LayerCode'],
'LayerName' => $layerDetails['LayerName'],
]);
foreach($menuItems as $item){
print_r($item);
$item = array('LayerDetails' => $item);
array_push($menuCategories['menuItem'][$value], $item);
foreach($item as $items => $itemValue)
array_push($menuCategories['menuItem'][$value][$itemValue], $itemValue);
}
}
}
}
echo "\n\n";
Array
(
[LCategory] => Council Assets
[LayerCode] => RBC/AL
[LayerName] => Available Land
)
Array
(
[LCategory] => Council Assets
[LayerCode] => RBC/COL
[LayerName] => Council Owned Land
)
Array
(
[LCategory] => Planning
[LayerCode] => DC/CA
[LayerName] => Conservation Areas
)
Array
(
[LCategory] => Planning
[LayerCode] => DC/LB
[LayerName] => Listed Buildings
)
Array
(
[LCategory] => Planning
[LayerCode] => DC/PA
[LayerName] => Planning Applications
)
Array
(
[LCategory] => Planning
[LayerCode] => DC/TPO
[LayerName] => Tree Preservation Orders
)
{
"menuItem": {
"Council Assets": [
{
"LayerDetails": {
"LCategory": "Council Assets",
"LayerCode": "RBC\/COL",
"LayerName": "Council Owned Land"
}
}
],
"Planning": [
{
"LayerDetails": {
"LCategory": "Planning",
"LayerCode": "DC\/LB",
"LayerName": "Listed Buildings"
}
},
{
"LayerDetails": {
"LCategory": "Planning",
"LayerCode": "DC\/PA",
"LayerName": "Planning Applications"
}
},
{
"LayerDetails": {
"LCategory": "Planning",
"LayerCode": "DC\/TPO",
"LayerName": "Tree Preservation Orders"
}
}
]
}
}