4
Let’s say I have 2 tables, one with phone numbers, and one with sectors:
Ex. tb_extensions: id, branch, group_id(fk).
id | ramal | grupo_id
01 | 1234 | 01
02 | 2345 | 01
03 | 3456 | 02
04 | 3457 | 02
tb_groups: id, sector, manager.
id | setor | gestor
01 | setorA | Carlos
02 | setorB | Jose
There is a way to obtain a sector-indexed associative array?
In such a way that all the data of the tables were available in a single array and through a single query, being possible to spend it as follows:
<?php
foreach ($resultado['setorA'] as $setorA) {
// código
}
foreach ($resultado['setorB'] as $setorB)
// código
}
Currently I can do this through two sql queries, assigning a clause where setor = 'setorX'
for each of them...
But I’d like to know if there’s a way to get to the same result by just doing a query and returning an industry-indexed associative array, and if, that would be good practice with a high number of data, where it’s necessary to consider, if it is interesting the volume of data in a single query, or if it is more interesting to do it in 2 queries, dividing the data into 2 arrays.
The doubt is ref. the pure mysql query, so it is not necessary to talk about PDO or other classes.
I’ll put the answer!
– user6026