显示评论
嘿伙计们,抱歉,如果这是一个业余问题,但我在这方面遇到了一些麻烦。
如何显示针对特定页面的评论? (page.php?id=48)
因为现在,每次我发表评论时,它都会显示在所有页面上,而不是我希望它发布在
继承人代码上的页面上:
$userfinal=$_SESSION['username'];
$rs = mysql_query("SELECT id FROM searchengine") or die(mysql_error());
$rec = mysql_fetch_assoc($rs);
$id = $rec['id'];
// get the messages from the table.
$get_messages = mysql_query("SELECT messages_id FROM messages WHERE to_user='$id' ORDER BY messages_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$id' ORDER BY messages_id DESC") or die(mysql_error());
$num_messages = mysql_num_rows($get_messages);
// display each message title, with a link to their content
echo '<ul>';
for($count = 1; $count <= $num_messages; $count++){
$row = mysql_fetch_array($get_messages2);
// if the message is not read, show "(new)"
// after the title, else, just show the title.
if($row['message_read'] == 0)
任何帮助将不胜感激,谢谢
Hey guys sorry if this is an amateur question but I'm having a little trouble with this.
How do I display comments towards a specific page? (page.php?id=48)
Because right now, every time i post a comment, it displays on all pages instead of the one i wanted it to post on
Heres the code:
$userfinal=$_SESSION['username'];
$rs = mysql_query("SELECT id FROM searchengine") or die(mysql_error());
$rec = mysql_fetch_assoc($rs);
$id = $rec['id'];
// get the messages from the table.
$get_messages = mysql_query("SELECT messages_id FROM messages WHERE to_user='$id' ORDER BY messages_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$id' ORDER BY messages_id DESC") or die(mysql_error());
$num_messages = mysql_num_rows($get_messages);
// display each message title, with a link to their content
echo '<ul>';
for($count = 1; $count <= $num_messages; $count++){
$row = mysql_fetch_array($get_messages2);
// if the message is not read, show "(new)"
// after the title, else, just show the title.
if($row['message_read'] == 0)
Any help would be appreciated, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看我的示例代码。
考虑一个具有基本结构的表
comments
。comment
列将保存您的评论文本article_id
保存其所属文章的外键。现在假设您想从特定的
articleid
article.php?id=48
检索评论,您应该这样做。
尽管我的代码与您的问题根本无关,但它应该为您提供如何实现逻辑的基本概念。
编辑:
你不应该使用代码进行生产,代码只是为了解释你实现逻辑,记住这段代码很容易受到SQL注入,如果你想要临时修复,你可以使用 mysql_real_escape_string() 函数来避免它。检查我更新的代码。
提示:您应该尝试对所有数据库查询使用 PDO,这里是帮助您入门的教程 http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
take a look at my sample code.
Consider a table
comments
with the basic structure.comment
column will hold the text of your commentarticle_id
holds the foreign key of the article it belongs to.now lets say you want to retrieve the comment from a particular
articleid
article.php?id=48
here is how you should be doing it.
although my codes does not relate to your question at all, but it should give you the basic idea on how to implement the logic.
EDIT :
you should not use the code for production, the code is only meant to explain you to implement the logic, remember this code is vulnerable to SQL injections, if you want a temporary fix you could use mysql_real_escape_string() function to avoid it. check my updated code.
TIP : you should try and use PDO for all your database queries here is the tutorial to get you started http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/