Jump to content

Recommended Posts

Okay, ill break this down for you:

 

I have a news system on my front page which uses the following table:

 

id_news

title_news

message_news

 

I also have a comment system which goes like this:

 

Which everytime you click on post comment, it gets the id of the message which you want to post a comment in and inserts the id in a table row called "id_int".

 

id_int = id_news

 

Now I want to show my users how comment each news has, but it doesnt work...

 

$Recordcount=mysql_query("SELECT * FROM comment INNER JOIN news ON id_int=id_news WHERE // here is where I am stuck
		$RecordResult=mysql_num_rows($Recordcount);

 

What should I put in the WHERE statement?

Link to comment
https://forums.phpfreaks.com/topic/62948-solved-i-cant-get-the-correct-query/
Share on other sites

K, there is a set of messages in my front page:

Tables:
id_news // The Id of the News
title_news // The title
message_news //My Message
date_news // And the Date (obviously)

[code]<?php
		include("config/connect1.php");
		$string= "SELECT * FROM news";
		$query= mysql_query($string);		

		while ($news = mysql_fetch_array($query)){
		$idcount= $news['news_id'];

		$Recordcount=mysql_query("SELECT count(subject_cmt) FROM comment INNER JOIN news WHERE id_int=1");
		$RecordResult=mysql_fetch_row($Recordcount);

		echo'
            <table width="100%" height="191"  border="0" cellpadding="0" cellspacing="2">
              <tr>
                <td height="16" bgcolor="#7CADC2"><div align="left" class="style30">  <img src="files/images/spacer.gif" width="1" height="1"><img src="files/images/spacer.gif" width="1" height="1"><img src="files/images/spacer.gif" width="1" height="1">' . $news['title_news'] . ' <span class="style17">- Posted by: Adminstrator on ' . $news['date_news'] . '</span></div></td>
              </tr>
              <tr>
                <td height="134" align="left" valign="top"><div align="left">
                    <span class="style29"><br>' . $news['message_news'] . ' 
         <br> </div></td>
              </tr>
              <tr>
                <td height="19" valign="top"><hr size="1" noshade></td>
              </tr>
              <tr>
                <td height="12" valign="top" class="style17"><div align="right" class="style200"> <a href="#">Suscribe</a> | <a href="?page=viewcomments&uid=' . $news['id_news'] . '">Comments</a> (' . $RecordResult['subject_cmt']. ')</div></td>
              </tr>
            </table>'; 
		}
		?>

 

So this is a simple code...

 

Every news is looped, and there is a link after each news that says comments.

 

When you click comment, the URL is this

 

<a href = ?page=viewcomment // The switch statement for viewing a comment

&uid=anything... // This is the id_news

 

Now the id is passed from the url to our comment page, and from there on we have a post comment link which goes like this:

 

<a href =?page=postcomment // THe switch statement for posting the comment

&uid=... //the id we got from the URL earlier

 

Now when you are done posting a comment, the uid goes in the comment table:

 

id_cmt // The id of the comment

id_int // The UID is placed in here

title_cmt

 

...

 

..

 

.etc

 

Now I want to show the number of comments within each news like this:

 

	$Recordcount=mysql_query("SELECT count(subject_cmt) FROM comment INNER JOIN news WHERE id_int=1");
		$RecordResult=mysql_fetch_row($Recordcount);

 

[/code]

 

It Doesnt work.

look the way you join is very wrong i dont know what yu wnat to join bu let me tell you this joining will condiotn like you are trying to join two tables having the same field records or data like field1=field2

 

i have here some stuff i know its not the exact but i think your idea will fall on to this

$Recordcount=mysql_query("SELECT count(subject_cmt) as total_count, subject_cmt FROM comment group by subject_cmt order by subject_cmt");

now this will output something like

subject_cmt = teng

total_count = number

note no join because i dont know the relationship of your tbl

 

KK listen, or read...

 

I have the frontpage, just imagine. You see three news posted in the frontpage, just imagine lol.

 

The id of the first news is "1", and you go post a comment, then you are directed to the post comment page.

 

In the post comment page, you see this in the URL of the page "?uid=1", so every news you post a comment to, the "?uid= ' The id of the news' "...

 

Hope we understand so far.

 

Now when you are done posting, this code is generated

 


$id_of_the_news=$_GET['uid'];

mysql_query("insert into comment_table (holder_of_id_of_the_news) VALUES ('$id');

 

So now when you want to view the comments of the news, you click comments and it sends you to view the comments..

 

This code Generates

 


$id_of_the_news=$_GET['uid']; //This is passed from the url

$string="SELECT * FROM comment INNER JOIN news ON holder_of_id_of_news = 'id_of_the_news' 
WHERE = '$id_of_the_news' "

$query=mysql_query($string);

while($row=mysql_fetch_array($query)){

ECHO ALL THE TABLES OF THE COMMENT

}

?>



Now I want to count the number of comments that are assigned to the news depending on the id of the news....

 

DOnt want to say your stupid by typing like this, please take no offense.

'SELECT COUNT(id) AS ID, news.title FROM Comment 
inner join News on News.id = Comment.id_int
goup by id_int order by ID'

 

try

it will count the rows from comment and display thetitle of the news

so it should output like

title of news and the ID which is the number of comment

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.