これは専門家にとってはかなり簡単かもしれませんが、初心者として助けが必要です. アイテムと添付ファイルを含む次の 3 つのテーブルがあります。以下の結果セクション (JSON 形式) に示すように、これらのデータを多次元配列に入力したいと考えています。
Tables - columns
items
- itemID
- itemTitle
- catID
attachments
- attachmentID
- itemID
- attachmentFilename
データベースに 2 つのアイテムがあり、最初のアイテムが 2 つの添付ファイルに関連し、2 番目のアイテムが 3 つの添付ファイルに関連していることを考えると、結果は次のようになります。
{
"items": [{
"item": {
"itemID": "1",
"itemTitle": "The first item",
"attachments": [{
"attachment": {
"attachmentFilename": "The First attachment.att",
"attachmentID": "1"
},
"attachment": {
"attachmentFilename": "The Second attachment.att",
"attachmentID": "2"
}
}]
}
},
{
"item": {
"itemID": "2",
"itemTitle": "The Second item",
"attachments": [{
"attachment": {
"attachmentFilename": "The Third attachment.att",
"attachmentID": "3"
},
"attachment": {
"attachmentFilename": "The Fourth attachment.att",
"attachmentID": "4"
},
"attachment": {
"attachmentFilename": "The Fifth attachment.att",
"attachmentID": "5"
}
}]
}
}]
}
上記の結果が得られるようにphpでコーディングする方法を知りたいです。事前にどうもありがとうございました。