Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Posts
    7

    Unanswered: 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);
    }
    }

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2008
    Posts
    7
    tnxz...it help some how...ejejeje..

  4. #4
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    ROFL..

    This message is too short

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •