Issue: Only one comment will display at a time.
So I built a photo sharing script where a logged in user can share photos with their friends and where the user or their friends can comment on the photos. I’ve got it so only your friends photos (as well as your photos) will show on the page. I also got it so that when you enter a comment it only shows for the specific photo you’re commenting on. The issue I’m running into is that only one comment is showing at a time. I want all comments for all photos to show at once. Here is the script I’m using to pull the pictures and comments:
PHP:
[CODE]//WHERE I GATHER COMMENT DATA
$sql = “SELECT comment, username, photo_file, date_time FROM comments ORDER BY id ASC”;
$query = mysqli_query($db_conx, $sql);
$commentlist = “”;
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$c = $row[“comment”];
$us = $row[“username”];
$pf = $row[“photo_file”];
$time = $row[“date_time”];
}
//WHERE I GATHER PHOTO DATA
$sql = “SELECT DISTINCT initiator, file, gallery FROM photos WHERE username=’$log_username’ OR initiator=’$log_username’ ORDER BY date_time DESC”;
$query = mysqli_query($db_conx, $sql);
$photolist = “”;
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$u = $row[“initiator”];
$file = $row[“file”];
$gallery = $row[“gallery”];
$image = ‘user/’.$u.’/’.$file;
//WHERE I DISPLAY THE PHOTO DATA
$imagelist .= ‘ <img height=”200″
onclick=”this.height=500;”
ondblclick=”this.height=200;” src=”‘.$image.'” alt=”‘.$u.'” /><br /> Added to <a href=”user.php?u=’.$u.'”><b>’.$u.”s</b></a> ‘.$gallery.’ gallery<br /><br />
<form action=”comments_system.php” enctype=”multipart/form-data” method=”post”>
<input type=”text” name=”comment”>
<input type=”hidden” name=”photo_file” value=”‘.$file.'”>
<input type=”submit” class=”submit” value=” Submit Comment ” />
</form><br /><p style=”border-bottom: 1px dotted #A0A0A0;”></p>’;
//WHERE I DISPLAY THE PHOTO COMMENTS AND DICTATE WHAT COMMENT SHOWS WITH WHAT PHOTO
if ($pf == $file) {
$imagelist .='<p style=”background-color:#E0E0E0;”> <b>’.$us.'</b>: ‘.$c.’ | ‘.$time.'</p>
<br /><br /><hr/>’;
}
}
HTML:
[CODE]<div id=”pageMiddle”>
<!– START Page Content –>
<div id=”notesBox”> <br /> <font size=4><b>Photos</b></font><br />
</br /><br />
<?php echo $imagelist; ?></div>
<div style=”clear:left;”></div>
<!– END Page Content –>
</div>
Again, the issue is that only one comment is showing up at a time. I’m looking for all comments to show under the respective photos. Any help you can give would be GREATLY appreciated. I’ve been trying to figure this out for weeks. ?