Basically what happens is this:
A person goes to a specific gallery, say GalleryID=42. I do a query to grab all of the images in that gallery (with the value of GalleryID=42), and do a separate query to grab all of the comments associated with that gallery (for example GalleryID=42). There may only be 4 comments total on 3 different pictures out of 400 total images.
As I loop through the images with a do/while loop, and display them, I search the array of comments that have been placed for each picture as it loops. If it finds the picture ID that matches a specific picture, it displays the comment values (Comment, CommentAuthor, and CommentDate).
Here is the query for the images:
SELECT * FROM GalleryData WHERE GalleryID = 42
And the query for the comments:
SELECT Comment, CommentAuthor, CommentDate, ID FROM Comments WHERE CategoryID=42
Then I use this code to put the comments in the reusable query:
while(($Comments[] = mysql_fetch_assoc($rsComments)) || array_pop($Comments));
Then I use this to this to loop through the array to find the comments associated with the particular picture
foreach($Comments as $comment)
{
if($comment['ID'] == $row_rsGalleries['ID'])
{
echo '<p>'.$comment['Comment'].' - '.$comment['CommentAuthor'].'</p>';
}
}
Problem is, that this code seems to not include the very first comment in the query.
Now, this is one of the first projects I have done something like this, and I am not a php/mysql expert, a novice user.
When I run the query, it comes up with 4 results, but the array only includes 3, the first result is missing.
bool
values onto$Comments
...mysql_fetch_assoc(...) || array_pop(...)
is evaluated before assignment, and the result will always be a bool. – meagar♦ Oct 7 '10 at 17:52|| array_pop($Comments)
?? – MatTheCat Oct 7 '10 at 17:53var_dump($Comments)
after the loop? – meagar♦ Oct 7 '10 at 17:54