0
我有2個多維數組,它從數據庫中的2個不同表中獲取數據。其中一人有3支球隊,另一支球隊有球隊的命令。如何根據另一個多維數組數據結果搜索多維數組數據
$sql = "select id, supervizori, grupi, tipo_crt, operatori, data, status, nome, cognome, cel, codice_fiscale from kontrata";
$result = mysqli_query($dbCon, $sql);
if(!$sql) {
die("Error1");
} //this query takes the orders from the kontrata table.
$sql_2 = "select * from grupi";
$result_2 = mysqli_query($dbCon, $sql_2);
if(!$sql_2) {
die("Error2");
} // this query take the teams from the grupi table.
while ($row = mysqli_fetch_assoc($result)) {
$kontratat[$row['id']]['supervizori'] = $row['supervizori'];
$kontratat[$row['id']]['grupi'] = $row['grupi'];
$kontratat[$row['id']]['tipo_crt'] = $row['tipo_crt'];
$kontratat[$row['id']]['operatori'] = $row['operatori'];
$kontratat[$row['id']]['data'] = $row['data'];
$kontratat[$row['id']]['status'] = $row['status'];
$kontratat[$row['id']]['nome'] = $row['nome'];
$kontratat[$row['id']]['cognome'] = $row['cognome'];
$kontratat[$row['id']]['cel'] = $row['cel'];
$kontratat[$row['id']]['codice_fiscale'] = row['codice_fiscale'];
} // In this loop i take the data according to the order table.
while ($row = mysqli_fetch_assoc($result_2)) {
$kontratat_2[$kontratat['id']]['grup_name'] = $row['grup_name'];
} // In this loop i take the teams.
我使用的foreach的數據dispay到一個表,但是當我打電話的foreach導致我得到的所有訂單(這是正常的),但我有100個訂單 那些3支球隊有使循環後。我想用secont循環過濾每個團隊的訂單。簡單地說,我可以用第一個查詢中的「ID」查看每個團隊的所有訂單,而不是將同一個團隊展示50次。謝謝:)
Array
(
[11] => Array
(
[supervizori] => data
[grupi] => Doctors //this is the team
[tipo_crt] => LUCE
[operatori] => data
[data] => 2015-12-20
[status] => OK
[nome] => data
[cognome] => data
[cel] => data
[codice_fiscale] => shkrfl93a08a123a
)
[12] => Array
(
[supervizori] => data
[grupi] => BMW //this is the team
[tipo_crt] => data
[operatori] => data
[data] => 2015-12-22
[status] => KO
[nome] => rgrg
[cognome] => grdgdrgdrg
[cel] => serges
[codice_fiscale] => a
)
[17] => Array
(
[supervizori] => data
[grupi] => Doctors //this is the team
[tipo_crt] => GAS
[operatori] => data
[data] => 2015-12-24
[status] => Atessa
[nome] => dscc
[cognome] => csdfvsg
[cel] => wgwegwe
[codice_fiscale] => rgrwgrwg
)
[18] => Array
(
[supervizori] => data
[grupi] => Bosat //this is the team
[tipo_crt] => data
[operatori] => data
[data] => 2015-12-24
[status] => OK
[nome] => dscc
[cognome] => csdfvsg
[cel] => wgwegwe
[codice_fiscale] => rgrwgrwg
)
[19] => Array
(
[supervizori] => data
[grupi] => Doctors //this is the team
[tipo_crt] => LUCE
[operatori] => data
[data] => 2015-12-29
[status] => Atessa
[nome] => dhr
[cognome] => rhrdh
[cel] => rdhrdh
[codice_fiscale] => rdhrdh
)
[20] => Array
(
[supervizori] => data
[grupi] => Doctors //this is the team
[tipo_crt] => LUCE
[operatori] => data
[data] => 2016-01-04
[status] => OK
[nome] => dwadwa
[cognome] => jgv
[cel] => jlgv
[codice_fiscale] => jgv
) // this is the first array from orders
Array
(
[8] => Array
(
[grup_name] => BMW
)
[9] => Array
(
[grup_name] => Doctors
)
[10] => Array
(
[grup_name] => Bosat
)
)// the teams array