Reputation: 1273
I have a table where I save images path from a folder in order to use them for blog posts and another table where I store the posts. The two tables are related so in the images table I have a postID. The paths are stored correctly in the database but when I try to display the actual images it only gets one image and displays it on all posts. I want to display a separate image for each post. I tried to use a query to make it take the record and display one different image for one post.
$select_img = "SELECT imgLoc FROM blog_images JOIN blog_posts on blog_images.postID = blog_posts.postID WHERE blog_images.postID = blog_posts.postID ORDER by imgID DESC";
$img_query = mysqli_query($link, $select_img) or die(mysqli_error($link));
$row2 = mysqli_fetch_array($img_query);
then I used echo '<img src="'.$row2['imgLoc'].'"'.'/>';
to display the actual image. However, this way it only displays one image to all posts.. Any suggestions?
Thanks!
Upvotes: 1
Views: 35
Reputation: 74
If i am understanding it right, you want to loop through the results of your fetch array.
while($row2 = mysqli_fetch_array($img_query)){
echo '<img src="'.$row2['imgLoc'].'"'.'/>';
}
I am writing it off from the top of my head, but a sort of looping mechanism hsould do the job
Upvotes: 1