kleb Posted January 25, 2012 Share Posted January 25, 2012 am having problem with showing specific comments on a specific topic created by users please visit the site:www.planetafric.com and click on the topics you will understand what am trying to say.i will post the code later but i want you to visit the site in other for you to understand what am trying to say .You will discover that the comment made on a topic(a) shows in topic(b) also which is not supposed to be so thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/ Share on other sites More sharing options...
nine7ySix Posted January 25, 2012 Share Posted January 25, 2012 Can you please clarify your problem? I have no idea what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1310949 Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 am having problem with showing specific comments on a specific topic created by users please visit the site:www.planetafric.com and click on the topics you will understand what am trying to say.i will post the code later but i want you to visit the site in other for you to understand what am trying to say .You will discover that the comment made on a topic(a) shows in topic(b) also which is not supposed to be so thanks so much you will need to provide us with the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1311031 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2012 Share Posted January 25, 2012 Have you checked if your data that relates the comment with the correct topic is correct in your database? Having someone observe the final incorrect result, doesn't help pin down where the problem is occurring at. Your code that accepts and stores the comment could be incorrect or your code that gets and displays the topic and comments could be where the problem lies. You need to pin down at what point in the entire process your code and data is doing what you expect and at what point they are not. I can guarantee that the problem lies somewhere between those two points. Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1311035 Share on other sites More sharing options...
kleb Posted January 25, 2012 Author Share Posted January 25, 2012 this is what i want to do: i want users to beable to comment on any topic that was created by other users which i have succesfully done but the problem i have is that when a new visitor clicks on the topics it just display all the content in the post table where the comments are inserted..i.e if i have topic(a) topic(b) and topic© and a user comments on topic© and i click on the topic© to view the comments it will not only show comment made on topic© but all the comments made on topic(a) and topic(b) on topic© page like wise if you click on topic(a) and topic(b) and any topics created further. this is my code:this is the page where the topics are created <h3>Topics</h3> <table> <tr> <th class="first"><strong>Category </strong></th> <th>Topic</th> <th>Post date</th> </tr> <tr class="row-a"> <td class="first"><?php include"header.php"; $sql="SELECT *FROM topics"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_cat']}"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT *FROM topics "; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<a href='comment.php?id={$row['topicsID']}'>{$row['topics_subject']}</a>"."</br>"; } ?></td> <td><?php include"header.php"; $sql="SELECT* FROM topics"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_date']}"."</br>"; } ?></td> </tr> </table> <h3>Post your topic here</h3> <form action='topic.php'method='post'> <label>Note:your write up should not be more than 200 words.thanks</label> Topic:<input type="text"name="topic"value="your topic goes here" /></br> Category:<input type="text"name="cat"value="E.g Politics,Sports.etc"/></br> Name:<input type="text"name="name"value="your name"/> <textarea name="content" id="content" style="width:300px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;">Your comment goes here.</textarea> <br /> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <blockquote>Please note that we welcome would-be person(s) that wish to write on our Editorial board from any part of the world.</br> If you are intrested kindly send your write up not more than 350 words with your personal photo and any image related to your article and forward it to Email:editorial@planetafric.com</br>Thanks so much.</blockquote> [code] this is the page that handles the topics <?php include"header.php"; if(isset($_POST['submit'])) { $topic=mysql_real_escape_string(trim($_POST['topic'])); $cat=mysql_real_escape_string(trim($_POST['cat'])); $by=mysql_real_escape_string(trim($_POST['name'])); $content=mysql_real_escape_string(trim($_POST['content'])); $dateTime = new DateTime("now", new DateTimeZone('GMT')); $date =$dateTime->format("Y-m-d H:i:s"); if($topic!=='' && $cat!=='' && $by!=='' && $content!=='') { $ins="INSERT INTO topics(topics_subject,topics_content,topics_cat,topics_date,topics_by)VALUES('$topic','$content','$cat','$date','$by')"; $inss=mysql_query($ins) or die(mysql_error()); if($inss) { echo "Your topic as been inserted<a href='page.php'> click here to view your topic(s)</a>"; } else { echo"There was a problem inserting your records please try again"; } } else { echo"You can not leave any field blank, please fill all fields"; } } ?> [/code] this is the page where comments are made: <p>Posted by <a href=""><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_by']}"; } ?></a></p> <p><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_subject']}"; } ?> <p align="left"><img src="speakout_1.png"/> <?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_content']}"; } ?> <p class="post-footer align-right"> <a href="" class="comments"><?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo"Comments:".$_SESSION['views']; ?></a> <span class="date"><?php include"header.php"; $topicid=$_GET['id']; $sql="SELECT*FROM topics WHERE topicsID=$topicid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['topics_date']}"; } ?></span> </p> </div> <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"></td> <td><?php include"header.php"; $sql="SELECT post_content,post_by FROM post ORDER BY topicsID"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } if(mysql_affected_rows()>0) { header("location:".$_SERVER['PHP_SELF']); } ?></td> </tr> </table> <h3>Post your comments here</h3> <form action='reply.php'method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <br /> </div> this is the code that handles the comments: <?php include"header.php"; if(isset($_POST['submit'])) { $comment=mysql_real_escape_string(trim($_POST['comment'])); $name=mysql_real_escape_string(trim($_POST['name'])); if($comment!=='' && $name!=='') { $ins="INSERT INTO post(post_content,post_by)VALUES('$comment','$name')"; mysql_query($ins) or die(mysql_error()); else { echo"You can not post an empty page or leave your name blank"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1311047 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2012 Share Posted January 25, 2012 You are not doing anything in your code to relate the comment with the corresponding topic, so of course there is no relationship. Your comment.php code needs to pass the $_GET['id'] value to the reply.php code and reply.php needs to store the topic id in the `post` table with the comment. You also need to STOP repeating the same query 3-4 times on one page. Just execute the query ONCE and then access the columns as you iterate over the data. You have a ton of excess code that makes it harder to see the forest (goal of the code) for the trees. Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1311067 Share on other sites More sharing options...
kleb Posted January 25, 2012 Author Share Posted January 25, 2012 am still confused.ok i will try to remove some of the codes Quote Link to comment https://forums.phpfreaks.com/topic/255730-help-this-is-killig-me/#findComment-1311092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.