我无法导出到CSV脚本。我只能一点一点地工作。它将从一个表下载,或者从另一个表下载,但不会两者都下载。基本上,我想要来自$get_asset
的某些字段和来自$customfields
的某些字段的标题和值查询。 array_merge
函数仅在$customfields
数组中将级别降低时将其从$fields
数组中拉出。我什至为foreach
数组尝试了$customfields
,但仍然无法正常工作。非常感谢您的协助。
/* ASSET INFO */
$get_asset = $pdo->prepare("SELECT * FROM assets WHERE type = ?");
$get_asset->execute([$type]);
$get_asset = $get_asset->fetchAll(PDO::FETCH_ASSOC);
foreach ($get_asset as $asset) {
/* ASSET TYPES */
$get_asset_type = $pdo->prepare("SELECT * FROM assets_type WHERE id = ?");
$get_asset_type->execute([$asset['type']]);
$get_asset_type = $get_asset_type->fetch(PDO::FETCH_ASSOC);
/* CUSTOM FIELDS */
$customfields = $pdo->prepare("SELECT * FROM assets_fields f LEFT JOIN assets_fields_values v ON f.id = v.fieldid AND v.related_asset = ? WHERE related_type = ? ORDER BY f.fieldorder ASC");
$customfields->execute([$asset['id'], $asset['type']]);
$customfields = $customfields->fetchAll(PDO::FETCH_ASSOC);
$fields = array_merge($asset, $customfields);
}