Reputation: 53
I wanted to properly organize my database result in the code so I can handle those result effectively and without much chaos. For eg.
id type prop value image_path is_primary
28 Leasable space Total built up area 10001 https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-0.jpeg 1
28 Leasable space Warehouse Identifier TEST_ARJUN https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-0.jpeg 1
29 Leasable space Warehouse Identifier TEST_ARJUN1 https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-1.JPG 1
29 Leasable space Total built up area 1001 https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-1.JPG 1
This is the data I fetch. Now according to primary keys (id) I want to make proper array structure. It will be mutli-dimensional like
arr[28][type]=Leasable Space
arr[28][prop][warehouseidentifier]=test_arjun
arr[28][prop][total built up area]=10001
So I am not able to form a way on how can make this structure effectively without any much of chaos. Or are there any good library which can help me do so. Any help would be appreciated.
Upvotes: 0
Views: 47
Reputation: 147256
Something like this should do what you want:
$arr = array();
while ($row = $result->fetch_assoc()) {
$arr[$row['id']]['type'] = $row['type'];
$arr[$row['id']]['prop'][$row['prop']] = $row['value'];
}
Upvotes: 1