| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
Displaying Comments for Articles
Ok, moving on, I am progressing well but have seemed to have come unstuck again. If I want to display the comments for a particular article how do I do this, I know its something to do with matching comment_ID with say article_ID. I have a table for comments and a table for articles. I then want to view the article, and click on view comments and go to a page with comments just for that article. Thanks in advance, |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Feb 2004
Location: Exeter
Posts: 773
|
Post the id number of the article in the url. ie $query = Select * from articles; $result = .... .... echo "<a href=http://www.mysite.com/view_comments.php?id=$row['id']>"; Then in the view_comments page, get the id from the url: $id = $_GET['id'] $query = "select from comments where article_id = $id" But you need a column in the comments table that identifies the comment with its related article |
|
|
|
#5 (permalink) |
|
Senior Member
Join Date: Feb 2004
Location: Exeter
Posts: 773
|
This might help: http://codegrrl.com/tutorials/cat_build_a_blog.php Its quite hard to explain without seeing all your code |
|
|
|
#6 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
ok, I have added article_id to my comments table in MySQL. viewComments.php Code:
blog.php Code:
I hope this is more clear, I had a look at that tutorial and its hurting my brain, I think I need to get a coffee and chill for a minute. It seems to be mre difficult then it should be. |
|
|
|
#8 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
I have just been checking through stuff, and when I look at the phpMyAdmin panel. I look at comments table and my column for article_id is always 0, the default is 0 but obviously I want it to pass the article_id from the articles page. Does that help solve where the problem is?? |
|
|
|
#9 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
Hey Joewebber, fixed the problem, I was just all confused with passing the right parameters and then in the record set I didn't set the article_id to = the url parameter of artice_id. So cool, did a little debugging and sorted it. While i'm on though there are a couple of other things that are stumping me, this is also for anyone who knows. But when I put in linespaces when I am entering data, it doesn't seem to show up in the dynamic table, that is it is showing continuous text with no line spaces between paragraphs. And also I want to show how many comments there are for an article, now when I use the built in function in DMX2004 it shows up all the comments and I only want the comments that are relative to that article. Cheers Nick |
|
|
|
#10 (permalink) | ||
|
Senior Member
Join Date: Feb 2004
Location: Exeter
Posts: 773
|
Quote:
It won't put them in. What you're entering is basically html code Quote:
Just write your query statements so it selects the comments for a given article, then use mysql_count_rows. (Don't know if thats the right syntax coz I'm a bit pissed) |
||
|
|
|
#11 (permalink) | ||
|
Senior Member
Join Date: Oct 2004
Location: Chester
Posts: 364
|
Quote:
Quote:
|
||
|
|
|
#12 (permalink) |
|
Iris Folder
Join Date: Apr 2003
Location: smokey
Posts: 2,650
|
If your entering line breaks in a form the text is entered as a plain text format ie uses \n for line breaks. For these to show up in your html table you will have to replace them with html tags (<br/>) using a php switchermajig. Smallbeers posted a good one a couple of times... mySql Advice |
|
|
|
#14 (permalink) |
|
Iris Folder
Join Date: Apr 2003
Location: smokey
Posts: 2,650
|
Searches for a regular expression in $text in this case "\n" and replaces it with the html code it needs "<br/>" $text = ereg_replace("\n",'<br />',$text); Does this for various elements to create the correct html markup. Returns the answer. |
|
![]() |