Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • It sounds like you’re going to try to do something in php that the database is much better suited to do... but if you look at the results of your query (showing all fields of both tables), a pattern should present itself. You could probably use the primary keys as the array indexes. I’m honestly not following what you’re trying to do because it sounds way more complicated than it should be. Remember, someone’s going to have to maintain this thing! Commented Nov 4, 2020 at 22:02
  • @TimMorton no, these tables have no patterns, I want to do the query in SQL and then put the results into a PHP array, but im not sure how to do that for a 3 dimensional array, for a 2 dimensional array I just use $row = mysqli_fetch_assoc($query) Commented Nov 4, 2020 at 23:36
  • could you give about 10 rows of results in your question? To achieve your goal with the array, you will have to use the db primary keys as keys of an associative array; that’s the only way you’ll be able to track the “table1 row”. Otherwise you’ll end up incrementing the first index with every db row. Commented Nov 5, 2020 at 0:06
  • It would probably be much easier to envision if you think of it as an array of arrays. The outer array represents each row of table 1, and the value stored in each array position is an array of the matching table 2’s rows. Commented Nov 5, 2020 at 0:12
  • @TimMorton that is precisely what I am asking about, how I would go about making this array of arrays Commented Nov 5, 2020 at 10:35