如何将div中的所有相关图像和相关注释显示为单独的div并重复新条目的包装div? [英] How do I display all the related images in a div and the related comment into a separated div and repeat the wrapping div for the new entry?
问题描述
我想在一个方框中同时显示所有相关的评论图片,但是在不同的div中显示评论。就像我附上的图片一样。
我想要的输出
HTML中的JavaScript示例
如果有新帖子,则用PHP重复主div。 />
我无法弄清楚我该怎么做。我假设我必须在某个地方打破循环。
数据库结构:
帖子:
| commentid |评论| iamgesid |
------------------------------------
| 1 |傻瓜| 5557 |
| 2 |傻瓜2 5585 |
------------------------------------
multiple_image:
| id |图片| imagesid |
---------------------------
| 1 | name1 | 5557 |
| 2 | name2 | 5557 |
| 3 | name3 | 5585 |
---------------------------
使用相关图像获取评论的代码:
$ sql =SELECT * FROM images
JOIN帖子ON(images.imagesid = posts .imgs)
ORDER BY postID;
$ result = $ conn-> query($ sql);
if(!$ result){
trigger_error('无效查询:'。$ conn->错误);
}
if($ result-> num_rows> 0){
//每行输出数据
$ comment ='';
while($ row = $ result-> fetch_assoc()){
if($ row ['name'] == NULL){
$ imgs ='';
} else {
$ imgs =< img width =''src ='.. / images /\".$ row ['name']。'>;
}
if($ comment!= $ row ['content']){
echo $ row ['content'];
$ comment = $ row ['content'];
}
echo $ imgs;
}
}
我尝试过:
我试图循环div,但它只是循环div本身。
sql =SELECT * FROM images
JOIN posts ON(images.imagesid = posts.imgs)
ORDER BY postID;
result =
conn->查询(
I want to display all the related images for a comment in a box together but display the comments in a different div Something like on the image that I have attached.
The output that I want to get
JSFiddle Example in HTML
If there is a new post then repeat the main div with PHP.
I can't figure out how should I do this. I assume that I have to break the loop somewhere.
The database structure:
posts:
| commentid | comment | iamgesid | ------------------------------------ | 1 | fool | 5557 | | 2 | fool2 | 5585 | ------------------------------------
multiple_image:
| id | image | imagesid | --------------------------- | 1 | name1 | 5557 | | 2 | name2 | 5557 | | 3 | name3 | 5585 | ---------------------------
The code for fetching the comment with the related images:
$sql = "SELECT * FROM images JOIN posts ON (images.imagesid=posts.imgs) ORDER BY postID"; $result = $conn->query($sql); if (!$result) { trigger_error('Invalid query: ' . $conn->error); } if ($result->num_rows > 0) { // output data of each row $comment = ''; while($row = $result->fetch_assoc()) { if ($row['name'] == NULL) { $imgs= ''; } else { $imgs= "<img width='' src='../images/".$row['name']."' >"; } if($comment != $row['content']){ echo $row['content']; $comment = $row['content']; } echo $imgs; } }
What I have tried:
I have tried to loop div as well but it is just looped the div itself.
sql = "SELECT * FROM images JOIN posts ON (images.imagesid=posts.imgs) ORDER BY postID";
result =
conn->query(
这篇关于如何将div中的所有相关图像和相关注释显示为单独的div并重复新条目的包装div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!