我正在使用两个查询从我的数据库中获取,当我尝试在每个查询中打印结果时,它确实打印了所有结果,但是当我尝试在外部打印时,它并没有打印所有内容:
$arr_devices = [];
$sql1 = "SELECT id FROM users WHERE users.name = '$company_name'"; //finding the ids of the users of this company
if ($res = $db->query($sql1)) {
$arr_id = $res->fetch_all(MYSQLI_ASSOC);
foreach ($arr_id as $company_id) {
$sql = "SELECT
devices.id,
devices.serial_imei,
devices.serial_no,
devices.type_id,
devices.cus_id,
devices.sales_date,
device_types.name,
device_types.manufacturer,
device_types.device_no,
device_types.barcode,
users.id,
users.name as manufacturer_name
FROM devices
INNER JOIN device_types
ON device_types.id = devices.type_id
INNER JOIN users ON device_types.manufacturer = users.id
WHERE devices.cus_id = " . $company_id['id'] . " ";
$result = $db->query($sql);
if ($result->num_rows > 0) {
$arr_devices = $result->fetch_all(MYSQLI_ASSOC);
}
print_r($arr_devices); //HERE IT PRINTS EVERYTHING I AM FETCHING
}
print_r($arr_devices); //HERE IT DOESNT
}
拉丁的传说