I have a table table1 with columns id and name. I also have a table table2 with columns table1_id and num. What I’m looking to do is get a php array that holds an associative array with name and the sum of the corresponding num. Right now I’m trying a foreach loop to cycle through table1’s ids and perform an inner join. How do I do this?
Share
For the query, you can use a
JOINwith a subquery that groups table2 by table1_id, and calculates the sum usingGROUP BY. To get the data into a associative array, usemysql_fetch_assoc: