帖子评论(PHP)

编程入门 行业动态 更新时间:2024-10-27 14:19:19
本文介绍了帖子评论(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在尝试在我的网站上使用评论.这些评论将用于我的帖子.

I'm currently trying to use comments on my website. The comments will be used on posts I have.

问题是,我目前正在使用iframe来显示它们.

The thing is, I'm currently using an iframe to show them.

我希望代码与我的帖子在同一页面上.

I would like the code to be on the same page as my posts.

我将通过发布代码向您展示我的意思:

I'll show you what I mean by posting my code:

comment_frame.php:

<?php if (isset($_POST['postComment' . $getid . ''])) { $post_body = $_POST['post_body']; $posted_to = "Chris"; $insertPost = mysql_query("INSERT INTO post_comments VALUES ('','$post_body','$user','$posted_to','0','$getid')"); echo "<p style='color: green'>Comment Posted!</p><br /><br />"; } // Get relevent comments $get_comments = mysql_query("SELECT * FROM post_comments WHERE post_id='$getid' ORDER BY id DESC"); $count = mysql_num_rows($get_comments); if ($count != 0) { while ($comment = mysql_fetch_assoc($get_comments)) { $comment_body = $comment['post_body']; $posted_to = $comment['posted_to']; $posted_by = $comment['posted_by']; $removed = $comment['post_removed']; echo "<b><a href='$posted_by' target='_blank'>$posted_by</a> said: <br /></b>".$comment_body."<hr /><br />"; } } else { // Do nothing! } ?>

home.php:

<?php // If the user is logged in $getposts = mysql_query("SELECT * FROM posts WHERE user_posted_to='$user' ORDER BY id DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_assoc($getposts)) { $id = $row['id']; $body = $row['body']; $date_added = $row['date_added']; $added_by = $row['added_by']; $user_posted_to = $row['user_posted_to']; $get_user_info = mysql_query("SELECT * FROM users WHERE username='$added_by'"); $get_info = mysql_fetch_assoc($get_user_info); $profilepic_info = $get_info['profile_pic']; if ($profilepic_info == "") { $profilepic_info = "./img/default_pic.png"; } else { $profilepic_info = "./userdata/profile_pics/".$profilepic_info; } ?> <script language="javascript"> function toggle<?php echo $id; ?>() { var ele = document.getElementById("toggleComment<?php echo $id; ?>"); var text = document.getElementById("displayText<?php echo $id; ?>"); if (ele.style.display == "block") { ele.style.display = "none"; } else { ele.style.display = "block"; } } </script> <?php echo " <br /> <div class='newsFeedPost'> <div class='newsFeedPostOptions'> <a href='javascript:;' onClick='javascript:toggle$id()'>Show Comments</a> <div style='float: left;'> <a href='$added_by'><img src='$profilepic_info' height='60' /></a> </div> <div class='posted_by'><a href='$added_by'>$added_by</a> wrote:</div> <br /><br /> <div style='max-width: 600px; height: auto;'> $body<br /><br /><br /><p /> </div> Like &ndash; Re-Shout! &ndash; Comment <br /><iframe src='./comment_frame.php?id=$id' frameborder='0' style='max-height: 200px; width: 100%; min-height: 10px;'></iframe> </div> </div> "; } } ?>

如您所见,它通过使用iframe显示了comment_frame.php页面.我希望所有这些代码都在一个页面中.我该怎么办?

As you can see it shows the comment_frame.php page by using an iframe. I would like all of that code to be in a single page. How would I do that?

推荐答案

在其他条件下输入您的home.php代码,如果用户添加新注释,则第一个条件将起作用,否则第二个条件

put ur home.php code in else condition if user adding new comment the first condition will work otherwise second one

if (isset($_POST['postComment' . $getid . ''])) { your code here }else { // home.php code herer }

更多推荐

帖子评论(PHP)

本文发布于:2023-10-23 08:21:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帖子   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!