我在MySql中创建了两个表,一个表保存了博客内容,另一个表保存了博客ID和不同的图片路径。我在一个postID中保存了多张图片。现在,我试图同时获取图片和博客文章,但无法正常工作。下面的代码...
blogposts.php
<?php
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($conn,"SELECT * , upload_data.FILE_NAME from blog_posts LEFT JOIN upload_data ON blog_posts.postID=upload_data.postID ; ");
while($row = mysqli_fetch_array($result))
{?>
<div class="b-slider j-smallslider" data-height="382">
<ul><?php
if (!empty($FILE_NAME)) {
$result = mysqli_query($conn,"SELECT * from upload_data where postID=postID ; ");
while($row = mysqli_fetch_array($result))
{?>
<li data-transition="3dcurtain-vertical" data-slotamount="12">
<img data-retina src="articles/user_data/<?php echo( htmlspecialchars( $row['FILE_NAME'] ) ); ?>">
</li> <?php }} ?>
</ul>
</div>
<div class="b-blog-one-column__info">
Title : <a href="#" class="f-more"><?php echo( htmlspecialchars( $row['postTitle'] ) ); ?></a>, <a href="#" class="f-more"><?php echo( htmlspecialchars( $row['postCat'] ) ); ?></a>
<span class="b-blog-one-column__info_delimiter"></span>
Tag : <a href="#" class="f-more">Nllam</a>
<span class="b-blog-one-column__info_delimiter"></span>
<a href="#" class="f-more f-primary"><i class="fa fa-comment"></i>12 Comments</a>
</div>
<?php } ?>
问题是我无法获取照片。 :(
最佳答案
使用此查询
$result = mysqli_query($conn,"SELECT blog_posts.* , upload_data.FILE_NAME from blog_posts,upload_data WHERE blog_posts.postID=upload_data.postID");
然后使用print_r()函数打印结果,并检查其获取结果与否。