0
我有此代碼哪些匹配在MySQL的視圖稱爲vAlbums
此返回查詢的JSON陣列導致PDO查詢另一個PDO查詢
function getAlbumPics($arno){
$aSql = "SELECT albu_ablumid, albu_name_en, albu_name_de, albu_name_fr, albu_name_nl, albu_name_es, albu_name_it, albu_photourl FROM vAlbums WHERE site_arno=:arno";
try {
$db = getConnection();
$aStmt = $db->prepare($aSql);
$aStmt->bindParam(":arno",$arno);
$aStmt->execute();
$albums = $aStmt->fetchAll(PDO::FETCH_OBJ);
$arrAID = $aStmt->fetchColumn(2);
$db = null;
echo '{"albums": ' . json_encode($albums) . '}';
} catch(PDOException $e) {
echo '{"error":[{"text":"'. $e->getMessage() .'"}],';
echo '"SQL": ' . json_encode($aSql) .'}';
}
}
我需要做一個子查詢將一個陣列在陣列中的每個專輯像這樣
{
"albums": [
{
"albu_ablumid": "1",
"photos": [
{
"photourl": "photo1"
},
{
"photourl": "photo2"
},
{
"photourl": "photo3"
}
]
},
{
"albu_ablumid": "2",
"photos": [
{
"photourl": "photo1"
},
{
"photourl": "photo2"
},
{
"photourl": "photo3"
}
]
}
]
}
照片可有人告訴如何實現這一目標的MySQL查詢的照片是:
SELECT * FROM photos WHERE album_id = x
謝謝
這是一個好主意,我想看看如果PHP/PDO路由將氾濫,如果可能的話,謝謝@Fluffeh –
剛試過這個,真棒謝謝 –