-1

well, question is like here: PHP/mySQL - how to fetch nested rows into multidimensinal array

its working (apart from adding too much columns), but what if I got more primary keys?

1 Answer 1

2

Doesn't matter, the same principle holds:

$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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

how to make this reference dynamic? I meant, sometimes "$data[$pk]", sometimes "$data[$pk1][$pk2]"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.