Assuming that from the previous answers you get the correct set of results from your SQL query:
SELECT * FROM `users` LEFT JOIN `images` ON images.id = users.id
i.e. a table of all users duplicating a row for each user based on the number of artist images that they have, or zeros in the col image if they don't have images
I think what you are missing in your PHP. You need to recognize the change in profile_ID in order to deflate your profile, and then in the inner loop your images, if any.
To do this, you must first save all the artistโs images.
Therefore, you set the first profile identifier, save the images, then when you reach the next profile identifier, you display everything before doing the same with the next, etc.
Note that the top if skipped on the first pass. Also note that variables that capture profile data are overwritten for each repeated line (sounds like 12 for your first profile in your test data), but since the data is the same, every time this is not a problem.
You need to remember the output of the last data set when exiting the main loop.
$result = $stmt->get_result(); $profile=$result[0]['id'] // initialise $imgs=array(); // inititalise foreach($result AS $row) { if($profile!=$row['id']) { $profile= $row['id']; echo "<div class='container team-wrap'> <div class='row'> <div class='col-md-6'> <img class='img-responsive' src='$image'> </div> <div class=\"col-md-6\"> <strong>$full_name<br>$job_title</strong> <br> <p>$bio</p> <a href='mailto:$email' class='btn btn-info'>Contact Me</a> </div> </div> </div>"; echo "<div class=\"container space team-wrap\"> <div class=\"row\"> <div class=\"col-lg-12\"> <div id=\"gallery-slider\" class=\"slider responsive\"> <div>"; foreach($imgs AS $img) { echo "<a target=\"_blank\" href=\"$img\"> <img src=\"$img\" alt=\"\"></a>"; } $imgs=array(); // Empty out image array echo " </div> </div> </div> </div> <hr> </div>"; } $full_name = $row['full_name']; $email = $row['email']; $job_title = $row['job_title']; $bio = $row['bio']; $ProfilePhoto = $row['profile_photo']; if (isset($ProfilePhoto) && ! empty($ProfilePhoto)) { $image = "$ProfilePhoto"; } else { $image = "avatar.jpg"; } if($row['artist_img']!==NULL) { $imgs[]= $row['artist_img']; } } /* Catch last one */ $full_name = $row['full_name']; $email = $row['email']; $job_title = $row['job_title']; $bio = $row['bio']; $ProfilePhoto = $row['profile_photo']; if (isset($ProfilePhoto) && ! empty($ProfilePhoto)) { $image = "$ProfilePhoto"; } else { $image = "avatar.jpg"; } echo "<div class='container team-wrap'> <div class='row'> <div class='col-md-6'> <img class='img-responsive' src='$image'> </div> <div class=\"col-md-6\"> <strong>$full_name<br>$job_title</strong> <br> <p>$bio</p> <a href='mailto:$email' class='btn btn-info'>Contact Me</a> </div> </div> </div>"; echo "<div class=\"container space team-wrap\"> <div class=\"row\"> <div class=\"col-lg-12\"> <div id=\"gallery-slider\" class=\"slider responsive\"> <div>"; foreach($imgs AS $img) { echo "<a target=\"_blank\" href=\"$img\"> <img src=\"$img\" alt=\"\"> </a>"; } echo " </div> </div> </div> </div> <hr> </div>";
Antg
source share