I use PHP 5.4 and MariaDB 5.6 I have one MYSQL table that contains records with the following:
network_id/size | ip_group | ip | subnet_owner | subnet_location
I want to build a multidimensional array directly from querying the database, is it possible? Why do I need it? I have checkboxes where if you check one IP, the checkbox should show up on the network_id/size and ip_group field. So I want to store them in layers, so I have to search through network_id/size only instead of going through all the records. Alternatively, if I check a whole network_id/size, I have instant access to all IDs.
- Every IP has an ip_group and a network_id/size
- groups are unique (there is no duplicate of IP and ip_group pair)
I wish my array to look as follows: network_id/size =>( ip_group =>( ip )))
Also, I would like all the records to be identified with its id as I could easily sort it and look for, let's say, IP in a particular network_id/size and group directly using binary search.
If I cannot build the array directly, what would be the most efficient way to build such an array without using double for loops with (O)n^2 time complexity?
I thought about grouping by network_id/size, putting that into an array, then group by ip_group add that to every array that has matching network_id/size and then does the same with IP, query for all IP and adds it where a matching group is.