Yet again...

Miscellaneous Forums/General Discussion/Yet again...

I need more PHP help. I'm wondering how I would create a script to display comments. I have a download table in my database, called "downloads" that holds all download information, including "id." There is a "downloadComment" table that holds all information regarding any comments made to a download. The downloadComment table holds a "downloadID" value, which corrosponds to the download table's "id" field.

I'm trying to get the script to count the number of entries in the downloadComment table, limiting it to the entries with the download table's id as the "downloadID."

Any ideas?

I guess it's a MySQL Database?

In MySQL you would use the WHERE command to filter things, eg.
    $sql = "SELECT
                Name,
                Email,
                Comment
            FROM
                Rubbish
            WHERE
                ID = '".$_GET['ID']."';";
    $result = mysql_query($sql) OR die(mysql_error());
    $row = mysql_fetch_assoc($result);
?>


Of course you first need to test with isset if the ID parameter is present etc.

An additional note: as long as you're not totally familar with the SQL and PHP synthax, I'd suggest to use unique variable and table names to prevent troubles with reserved words, example: TIME etc...
How about:
steve_name
steve_id
etc

I'm using that code above already to filter the comments - I just need to know how to count the entries in that table.

mysql_num_rows --> http://at2.php.net/manual/en/function.mysql-num-rows.php

Thanks, Marcus!

    $idfuntime = $row['id'];
    $query2 = "SELECT id, downloadid FROM downloadComment ORDER BY id DESC WHERE downloadid = $idfuntime"; 
    $result2 = mysql_query($query);
  $count = mysql_num_rows($result2);
    echo '<a href="downloads.php?view='.$row['id'].'">Comments:'.$count.'</a>';

For some reason, $count always equals 1. I'm not sure how to change this...Please help!

Any ideas? I really want this fixed...

OK, I fixed it. Thank you!