如何在PHP的mysql中只显示一次注释? [英] How display the comment only once from mysql in PHP?

查看:75
本文介绍了如何在PHP的mysql中只显示一次注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子:multiple_image和帖子



数据库结构===>



 multiple_image:

| id |图片| imagesid |
--------------------------
| 1 |名字| 5557 |
| 2 |名字| 5557 |
| 3 |名字| 5585 |
--------------------------



帖子:

| commentid |评论| iamgesid |
------------------------------------
| 1 |傻瓜| 5557 |
| 2 |傻瓜2 5585 |





我想要实现的输出是:

我想要显示所有图像对于具有相同imagesid的评论,但我的问题是,评论正在重复。



我尝试了什么: < br $>


 $ sql =SELECT image,posts.imagesid,multiple_image.imagesid,comment 
FROM multiple_image JOIN post ON(multiple_image.imagesid = posts.imagesid);
$ result = $ conn-> query($ sql);

if(!$ result){
trigger_error('无效查询:'。$ conn->错误);
}

if($ result-> num_rows> 0){

//每行输出数据
while($ row = $ result-> fetch_assoc()){

echo $ row ['comment'];
$ imgs =< div id ='img_div'>< img width =''src ='upload /\".$ row ['image']。'>< / div> ;
echo $ imgs;
}
}

解决方案

sql =SELECT image,posts.imagesid,multiple_image.imagesid,comment
FROM multiple_image JOIN帖子ON(multiple_image.imagesid = posts.imagesid);


result =


conn-> query(

I have two tables: multiple_image and posts

The db structures ===>

multiple_image:

| id |  image | imagesid |
--------------------------
| 1  |  name  |    5557  |
| 2  |  name  |    5557  |
| 3  |  name  |    5585  |
--------------------------


posts:

| commentid |  comment  | iamgesid |
------------------------------------
|     1     |   fool    |   5557   |
|     2     |  fool2    |   5585   |



The output that I am trying to achieve is:
I want to display all the images for a comment which has the same imagesid, but my problem is that, the comment is repeating itself.

What I have tried:

$sql = "SELECT image, posts.imagesid, multiple_image.imagesid, comment
        FROM multiple_image JOIN posts ON (multiple_image.imagesid=posts.imagesid)";
$result = $conn->query($sql);

if (!$result) {
    trigger_error('Invalid query: ' . $conn->error);
}

if ($result->num_rows > 0) {

    // output data of each row
while($row = $result->fetch_assoc()) {

echo $row['comment'];
$imgs= "<div id='img_div'><img width='' src='upload/".$row['image']."' ></div>";
echo $imgs;
}
}

解决方案

sql = "SELECT image, posts.imagesid, multiple_image.imagesid, comment FROM multiple_image JOIN posts ON (multiple_image.imagesid=posts.imagesid)";


result =


conn->query(


这篇关于如何在PHP的mysql中只显示一次注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆