Would like to use GROUP_CONCAT in order to retrieve database info (images) from a userid with multiple image entries. These images are in the form of a file path. Would then like to have the images output in a single row per userid.
After extensive research on the matter, I find simple examples of what is needed, but I get lost with the query I currently have in place.
Here is my code as of now:
<table>
<th></th>
<th>Name</th>
<th>Location</th>
<th>High School</th>
<th class="thLargest">Colleges</th>
</table>
<table>
<?php
session_start();
$conn = mysqli_connect("", "", "", "");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT college.id, college.title, GROUP_CONCAT(college.image) AS cImage, users.profileImage, users.fname, users.lname, users.level AS ulevel, users.city, users.state, users.highschool, users.primarysport, usercollege.id, usercollege.collegeid
FROM college, users, usercollege
WHERE usercollege.collegeid = college.id AND usercollege.userid = users.id
ORDER BY usercollege.createdate ASC";
if ($result = mysqli_query($conn, $sql)) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row['status'] == null) {
echo "";
}
if ($row['ulevel'] == "A Profile") {
echo '<tr>' .
'<td class="small">' . '<a href="http://www.example.com/aprofile.php?user="'.$row["username"] . '>' . '<img src="'.$row['profileImage'].'" />' . '</a>' . '</td>' .
'<td class="large">' . $row['fname']. ", " . $row['lname'] . '</td>' .
'<td class="large">' . $row['city'] . ", " . $row['state'] . '</td>' .
'<td class="large">' . $row['highschool'] . " (" . $row['primarysport'] . ") " . '</td>' .
'<td class="largest">' .
'<div class="Limage">' . '<img src="images/colleges/'.$cImage.'"/>' . '</div>' .
'</td>' .
'</tr>';
}
}
mysqli_free_result($result);
}
mysqli_close($conn);
?>
</table>
The image portion in question is '<img src="images/colleges/'.$cImage.'"/>' . '</div>'.
A user could have up to 10 entries of college images, so i'd like to display these images side by side, rather than displayed in a different row with the same userid.
In other words, I'd like to group multiple rows of user data from the database in a single row with no duplicate userid in the table.
I've read about exploding the cImage and using foreach as well, but that's where my lack of experience gets me.