Jump to content

built a news system for my website- need a little help, tho


sirstrongbad

Recommended Posts

okay. the file in question is:

 

http://graphicintegrity.net/newhtml/list_news.php

 

i would like to display the number of comments to each particular article, but no matter how i set my SQL statement up, it always returns the same number for every article. as it is now, it is showing the total number of comments made.

 

i have two tables for this. news_comments and news_content. here\'s my SQL statement thus far:

 

  $total_comments = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM news_content con, news_comments com WHERE com.news_id = con.id"),0);

 

i keep looking at it and it makes sense. there may be 100+ comments with the same news_comments.news_id value referencing a particular news.id value, but it always shows the total.

 

help please? i\'m somewhat \"new\" to this whole php/mysql thing. i followed quite a few tutorials to get to where i have this thing now. thanks in advance![/code]

Link to comment
Share on other sites

You need to specify which item. You are counting the total number of comments which have corresponding content items.

 

$conid = somevalue;

 

$total_comments = mysql_result(mysql_query(\"SELECT COUNT(*) as Num FROM news_content con, news_comments com WHERE com.news_id = con.id AND con.id = $conid \"),0);

 

or, for totals of each con.id :

 

$total_comments = mysql_result(mysql_query(\"SELECT con.id, COUNT(*) as Num FROM news_content con, news_comments com WHERE com.news_id = con.id GROUP BY con.id \"),0);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.