I have two tables named "Accounts" and "Images".
Images will contain multiple results for each account.
How do I reflect all the images associated with an account using mysql and php in an single array with all images separated by comma?
I am not certain which join to use either...
Here is what I expect my end result to be:
Array
(
[0] => Array
(
[id] => 1
[firstName] => "John"
[lastName] => "Doe"
[images] => "image1.jpg,image2.jpg,image3.jpg"
)
)
Here is what I currently get:
Array
(
[0] => Array
(
[id] => 1
[firstName] => "John"
[lastName] => "Doe"
[filename] => "image1.jpg"
)
)
Here is my code thus far:
$sql = SELECT a.firstName,a.lastName,i.fileName FROM accounts a INNER JOIN images i ON a.id = i.accountID;
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($result)){
$accounts[] = $row;
}
print_r($accounts);
If there is a better way for me to start than using the code above I am open to all suggestions.