好的伙计们,下面的代码运行正常。除了因为我为用户提供了最多4个图像下载,产品预览页面应该只显示其中一个图像,如产品页面中阵列中的第一个图像,但如果用户上传了4个图像,则显示所有行。我怎么能限制这个?感谢。
<?php
echo 'Your posts:' . '<br>' . '<hr>';
$posts = "SELECT * FROM posts,image_data WHERE userid='$user' AND user_posts.userid = image_data.client_id ORDER BY date_created ASC";
$posts_result = $mysqli->query($posts);
while ($posts_result_rows = $posts_result->fetch_assoc()) {
$its_id = $posts_result_rows["userid"];
$its_title = $posts_result_rows['post_title'];
$its_image = $posts_result_rows['file'];
$its_description = $posts_result_rows['post_description'];
?>
<table border=0 cellpadding=5 cellspacing=0 >
<tr>
<?php echo '<br>' . $its_title . ' <br>' . $its_description . '<br>'; ?>
<img src="<?php echo "users_data/users_posted_data/".$its_image; ?>" alt="<?php echo $its_title; ?>" width="120" height="120"><hr>
</tr>
</table>
<?php
}
?>
答案 0 :(得分:0)
尝试添加LIMIT 1
$posts = "SELECT * FROM posts,image_data WHERE userid='$user' AND user_posts.userid = image_data.client_id ORDER BY date_created ASC LIMIT 1";
$posts_result = $mysqli->query($posts);
答案 1 :(得分:0)
<?php
echo 'Your posts:<br><hr>';
$posts = "SELECT * FROM posts,image_data WHERE userid='$user' AND user_posts.userid = image_data.client_id ORDER BY date_created ASC";
$posts_result = $mysqli->query($posts);
while ($posts_result_rows = $posts_result->fetch_assoc()) {
$its_id = $posts_result_rows["userid"];
$its_title = $posts_result_rows['post_title'];
$its_image = $posts_result_rows['file'];
$its_description = $posts_result_rows['post_description'];
echo "<table border=0 cellpadding=5 cellspacing=0 ><tr><td>";
echo '<br>' . $its_title . ' <br>' . $its_description . '<br>';
}
?>
<img src="<?php echo "users_data/users_posted_data/".$its_image; ?>" alt="<?php echo $its_title; ?>" width="120" height="120"><hr>
</td></tr>
</table>
答案 2 :(得分:-1)
重要的是添加limit 1
。
SELECT * FROM posts,image_data WHERE userid='$user' AND user_posts.userid = image_data.client_id ORDER BY date_created ASC limit 1