View Full Version : State article with its comments
vividona
10-19-2008, 07:57 AM
I have 2 tables one for articles and the other for comments
how can I fetch the comments of each article
now when I made fectching all comments show in the first article
I need to state every article with it's comments
plz I need code example also
BBarash
10-19-2008, 01:16 PM
Within your articles table, make sure each one has a unique id. Then in your comments table make sure you have an article id field.
Every time a comment is submitted into the comments table make sure it is inserted with the article id field that is necessary to it.
Then on the PHP side of things. To display all the relevant comments for each article, at the bottom of the article's page have something like:
<?php
$query = mysql_query("SELECT * FROM comments WHERE `articleid` = '$tutid'");
while($row = mysql_fetch_array($query)){
echo $row['commentitle'] . "<br />" . $row['commentauthor'] . "<br />" . $row['comment'];
}
?>
vividona
10-19-2008, 01:42 PM
Oooh I got the trick
I am trying it now
plz keep in touch to give you the result
BBarash
10-19-2008, 01:49 PM
No problem, just ask here again if you need anything else.
Benji, shouldn't you escape the string?
BBarash
10-19-2008, 02:22 PM
Yeah, you definitely should - I was just typing up a basic example of how to while loop out data from a database table.
It's also worth doing htmlentities sometimes for extra security against malicious code injections.
vividona
10-24-2008, 03:30 AM
hi BBarash
everything is ok
my funny script work very good specially comments.
thx again and again
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.