drkjzk3359 2012-05-06 04:45
浏览 14

如何在相应的文章下显示评论

please i need your help with my script. I have a website whereby some content headers are put into an archive box, so that when the headers are clicked the content displays. My issue is about the comment that are made on each page.

Normally i pass the page ID with a GET, so if the GET is not set, that means, the article on display is the current article, and the id for it is passed into the WHERE query manually.

The problem is that the comments left by users on old archives article are not displayed on their respective article pages, but on the article of which i passed the ID manually. How can i fix this problem

Here is a bit of the code i'm trying to make work.

Thanks for your time and patience.

                   $page_name = 'about'; 
                    $id = "";
                    if (isset($_GET['id'])) {
                    $id = $_GET['id'];
  //display content based on the header       clicked
  } else {
  //display content of the current article       based on the id. I pass the numeric id              of the current article into the where       clause that selects the content
   //it displays
  }




 $query6 = mysql_query(" SELECT c.body          FROM comment AS c  
     INNER JOIN about AS a ON
     c.article_id = a.about_id
     WHERE   c.article_id =  3
     AND page_name = '".$page_name."'")

Comment Table

 CREATE TABLE IF NOT EXISTS`comment`(
     `comment_id` int(255),
     `article_id` int(255),
     `username` varchar(255) ,
     `page_name` varchar(255) ,
     `comment_body` varchar(300),
     `comment_date` datetime,
     PRIMARY KEY (`comment_id`)

About Table

  CREATE TABLE IF NOT EXISTS `about` (
  `about_id` int(255),
  `about_head` varchar(255)
  `about_content` varchar(4000),
  `about_tags` varchar(255) ,
  `about_created` datetime,

the URL for old articles

http://localhost/root/about.php?id=3

while the URL for the current article is

 http://localhost/root/about.php

so as it is now the current article doenst pass any dynamic id. if i do '".$id."' in the query, and i click the current article nothing is displayed.

  • 写回答

1条回答 默认 最新

  • duanhuan7750 2012-05-06 05:48
    关注
     WHERE   c.article_id =  3
    

    should presumably be

     WHERE   c.article_id =  $id
    

    Although PLEASE note that would be vulnerable to SQL injection. You should instead use prepared statements, into which you pass your variables as parameters that do not get evaluated for SQL. If you don't know what I'm talking about, or how to fix it, read the story of Bobby Tables.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题