How can I get data from a mysql query in a single row when selecting data from two tables using a join?
"id" "itemId" "itemTempId" "itemName" "userId" "postId"
"1" "US1" "T001" "Samsung Galaxy Note 5" "1" "1"
"id" "itemId" "itemTempId" "itemImageName" "userId" "postId"
"1" "US1" "T001" "front.jpg" "1" "1"
"2" "US1" "T001" "side-left.jpg" "1" "1"
"3" "US1" "T001" "side-right.jpg" "1" "1"
"4" "US1" "T001" "back.jpg" "1" "1"
Right now, when I do like below to select 1 row from the first table and related rows from the second table, I get all data in every row which also repeats when I print it using php.
select a.itemName, b.itemImageName from amga a left join amgb b on a.userId = b.userId where a.userId = 1;
Current Output
"itemName" "itemImageName"
"Samsung Galaxy Note 5" "front.jpg"
"Samsung Galaxy Note 5" "side-left.jpg"
"Samsung Galaxy Note 5" "side-right.jpg"
"Samsung Galaxy Note 5" "back.jpg"
Desirable Output or some other variation that wont repeat the itemName and that can easily be output using php.
"itemName" "itemImageName"
"Samsung Galaxy Note 5" "front.jpg","side-left.jpg","side-right.jpg","back.jpg"
In the final results the title is output only once, whereas the image names need to be looped through. Like this:
"Samsung Galaxy Note 5"
"front.jpg","side-left.jpg","side-right.jpg","back.jpg"