Hello,
I’m using three MySQL tables with the following names and field structures:
Table: comment
Fields: commentid, loginid, submissionid, comment, datecommented, level
Table: login
Fields: loginid, username, password, email, actcode, disabled, activated, created, points
Table: submission
Fields: submissionid, loginid, title, url, displayurl, datesubmitted
OK, the code below works great. It prints out an HTML table with the 10 most recently added “titles” from the MySQL table “submission.” It also prints out which “username” has the same “loginid” as the “title.”
Each “title” in the HTML table below has a unique “submissionid.” This same “submissionid” may appear multiple times or not at all in the MySQL table “comment.” What I would like to do is count the number of times any given title’s “submissionid” appears in the MySQL table “comment,” and then print this total below where “countComments” appears.
So I would just like to add the total comments for each submission right next to where the submitter’s username is currently showing up.
How can I do this?
Thanks in advance,
John
$sqlStr = "SELECT s.loginid, s.title, s.url, s.displayurl, l.username
FROM submission AS s,
login AS l
WHERE s.loginid = l.loginid
ORDER BY s.datesubmitted DESC
LIMIT 10";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\\"samplesrec\\">";
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td class="sitename1"><a href="http://www.'.$row["url"].'">'.$row["title"].'</a></td>';
echo '</tr>';
echo '<tr>';
echo '<td class="sitename2"><a href="http://www...com/sandbox/members/index.php?profile='.$row["username"].'">'.$row["username"].'</a><a href="http://www...com/sandbox/comments/index.php?submission='.$row["title"].'">'.$row["countComments"].'</a></td>';
echo '</tr>';
}
echo "</table>";