#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Posts
    910
    Rep Power
    0

    Count is not working


    I am using the code below I want a count beside each link but when I use it only 1 record link shows, why I do not use the count all links show why?

    PHP Code:
    while ($row mysql_fetch_array($result))
            {
    extract($row);
    $result mysql_query("SELECT * FROM answers WHERE qid ='qid'");
    $num_rows mysql_num_rows($result);


    print 
    "<a href=\"?tab=View Question&qid=$qid\">$question</a> - Votes: $num_rows<br>"



    Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    Just wondering if it's not supposed to be this (I think you've left the $ off the $qid variable in your query)?
    PHP Code:
    $result mysql_query("SELECT * FROM answers WHERE qid ='$qid'"); 
    If your query is right, look at how many answers have the value for qid set as 'qid' and you'll find how many answers there are for that question.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Posts
    910
    Rep Power
    0
    Yes I fixed that but it still does not work
    Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    Then echo out the query, and run that directly against your DB, using something like phpMyAdmin or whatever other DB management tool you have.
    PHP Code:
    $query "SELECT * FROM answers WHERE qid ='$qid'";
    echo 
    "<p>".$query."</p>";
     
    $result mysql_query($query); 
    That will tell you the results from that query. The most likely cause of this is that there is only one answer in your DB for that question ID.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0
    Try using back tick around the table name.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,927
    Rep Power
    378
    What does the query that builds the first result look like?

    And can you provide a SHOW CREATE TABLE for each of the relevant tables?
  12. #7
  13. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,047
    Rep Power
    487
    You're using $result twice and I suspect that's the reason.

    PHP Code:
    while ($row mysql_fetch_array($result))    <--- HERE
            
    {
    extract($row);
    $result mysql_query("SELECT * FROM answers WHERE qid ='qid'");
    $num_rows mysql_num_rows($result); <---- HERE


    print "<a href=\"?tab=View Question&qid=$qid\">$question</a> - Votes: $num_rows<br>"

    I recommend calling the 2nd $result something else such as $sub_result or $whatever_you_want_to_call_it_just_as_long_as_its_not_called_result

IMN logo majestic logo threadwatch logo seochat tools logo