Thanks for all the info everyone. So it looks like a UNION or even a UNION ALL clause isn't going to work. The two tables in question do not have the same number of columns or rows and not all data types are necessarily "compatible."
So I guess I'm sort of back to square one on this unless the JOIN clause will work for my situation. However, everything I've read on JOIN clauses gets really confusing and I'm unable to duplicate the examples I run across for my purposes. So here is what I had set up before attempting the UNION clause and the issue I was having:
//WHERE I GATHER COMMENT DATA
$sql = "SELECT comment, user, file, date_time FROM comment ORDER BY id ASC";
$query = mysqli_query($db_conx, $sql);
$commentlist = "";
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$c = $row["comment"];
$us = $row["user"];
$pf = $row["file"];
$time = $row["date_time"];
}
}
//WHERE I GATHER PHOTO DATA
$sql = "SELECT DISTINCT initiator, file, gallery FROM photo 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="php_parsers/photocomments_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/>';
}
}
You'll notice in the code above I'm using a "SELECT DISTINCT" clause for gathering the photos. This is necessary because the username that uploaded and the photo file names are duplicated multiple times in the table for notification purposes. If there was no "SELECT DISTINCT" clause the same photo would show multiple times.
Anyway, here is the issue and how it looks from a user perspective.
Because the photo query is being run second the photos show just as they should.
When a user attempts to comment on a photo, the comment is shown for the specific picture however only one comment shows at a time:
Notice that the "Nice picture!" comment overrode the "This looks yummy!" comment above:
So basically the script is only displaying one comment from the comment table at a time rather than showing all comments at once. If I swap the queries only one photo will show at a time and all of the comments will show at once. Is there anything you can see in my script that I could change that would allow all comments to show at once along with the photos? I'm hoping it's as easy as altering the "if" statement at the end of the script. I'm REALLY hoping I can avoid having to do a JOIN clause since I have a hard time wrapping my head around the formatting but if that's what I need to do so be it.
Again, any help you could give would be GREATLY appreciated.
Thanks!