If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > problem in getting the number of rows..pls help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-08, 22:38
mahyang mahyang is offline
Registered User
 
Join Date: Jun 2008
Posts: 7
problem in getting the number of rows..pls help

I've 2 tables which are article table and comments table, the 2 tables have d same id, the problem is i've to get the number of comments in a particular article. but my codes is not functioning....
f u've tym guyz check my code below..

$num=0;
$result ="";
$res_comment=$connector->query("SELECT * FROM article, comments WHERE comments.id = article.article_id ");
$resultquery=mysql_query($res_comment);
$num =mysql_num_rows($resultquery);

if($num==0)
{
$result = "Leave Comment";
}
else
{

$result =$num;
while($variable=mysql_fetch_assoc($resulquery))
{
extract($variable);
}
}
Reply With Quote
  #2 (permalink)  
Old 06-30-08, 22:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by mahyang
f u've tym guyz
OMG WTF BBQ!!!1!1

Code:
SELECT article.* 
     , c.no_of_comments
  FROM article
INNER
  JOIN ( SELECT article_id
              , COUNT(*) as no_of_comments
           FROM comments 
         GROUP BY article_id ) AS c
    ON c.article_id = article.id
no php plz, dis be da mysql forums

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-01-08, 00:43
mahyang mahyang is offline
Registered User
 
Join Date: Jun 2008
Posts: 7
tnxz...it help some how...ejejeje..
Reply With Quote
  #4 (permalink)  
Old 07-01-08, 04:51
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
ROFL..

This message is too short
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On