好吧,问题就在这里:PHP/mySQL - how to fetch nested rows into multidimensinal array
它的工作(除了添加太多的列),但如果我有更多的主键怎么办?
答案 0 :(得分:2)
无关紧要,同样的原则也适用:
$sql = <<<EOL
SELECT table1.pk AS pk1, table2.pk AS pk2, table3.pk AS pk3, etc...
FROM yourtable
LEFT JOIN ...
EOL;
$result = mysql_query($sql) or die(mysql_error());
$data = array();
while($row = mysql_fetch_assoc($data)) {
$data[$pk1][$pk2][$pk3][etc...] = $row;
}