【发布时间】:2016-06-18 22:30:48
【问题描述】:
这个页面应该从 post 表中回显帖子,并将它们与 images 表中具有相同 post_id 的图像链接。每个帖子可以包含多个图像或根本没有图像。我希望能够回显链接到特定帖子的所有图像。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("db.php");
$select_post = "select * from post as p
union
select img from images as i
on i.post_id = p.post_id";
$run_post = mysqli_query($conn, $select_post);
while ($row_post=mysqli_fetch_array($run_post)){
$post_id = $row_post['post_id'];
$post_title = $row_post['post_title'];
$post_date = $row_post['post_date'];
$post_author = $row_post['post_author'];
$post_content = substr($row_post['post_content'],0,100);
$post_image = $row_post['img'];
$post_image .= '<img src="post_image/'.$post_image.'" width="60" height="60"/>';
?>
<tr align="center">
<td><?php echo $post_id; ?> </td>
<td><?php echo $post_date; ?></td>
<td><?php echo $post_author; ?></td>
<td><?php echo $post_title; ?></td>
<td><?php echo $post_image; ?></td>
<td><?php echo $post_content; ?></td>
<td><center><button><a href="delete.php?del=<?php echo $post_id;?>" style="text-decoration:none; color:red; font-weight:bold;">X</a></button></center></td>
<td><center><button><a href="edit.php?edit=<?php echo $post_id;?>" style="text-decoration:none; color:red; font-weight:bold;"">Edit</a></button></center></td>
</tr>
<?php
}
?>
【问题讨论】: