-1

好吧,问题就像这里:PHP/mySQL - how to fetch nested rows into multidimensinal array

它的工作(除了添加太多的列),但如果我有更多的主键呢?

4

1 回答 1

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;
}
于 2012-05-06T11:22:45.477 回答