0
Display record count in a comments application
New Here
,
/t5/coldfusion-discussions/display-record-count-in-a-comments-application/td-p/231999
Jun 11, 2008
Jun 11, 2008
Copy link to clipboard
Copied
Hi, in my application, i try to display the number of
comments for each subject in a list. The problem is that the total
number of records are returned by the loop query for each subject,
even if the there is no comments for the subject related. Anybody
can help me? Here is the code :
<cfquery name="Qsujets" datasource="Modules_Web">
SELECT *
FROM dbo.Sujet
ORDER BY SUJ_ID
DESC
</cfquery>
<cfquery name="Qcommentaire" datasource="Modules_Web">
SELECT *
FROM dbo.Commentaire
</cfquery>
<html>
<head>
<title>Liste des sujets</title>
<link href="/sites/1676/commentaires/CSS/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Liste des articles </h1>
<br />
<cfoutput query="Qsujets">
<ul><li>
<span class="sujets">#Qsujets.SUJ_Nom#</span><br />
<span class="auteur">#Qsujets.SUJ_Auteur#</span><br />
<span class="description">#Qsujets.SUJ_Description#</span><br />
<div id="bloc_sujet">
<table>
<tr>
<td><img src="/sites/1676/commentaires/images/oeil.gif" alt="Lire les réactions " width="20" height="20" /></td>
<td><a href="/index.cfm/2,0,1676,9914,2832,0,html?COM_ID=#Qsujets.SUJ_ID#">Lire les réactions à cet article </a> (#Qcommentaire.RecordCount#)</td>
<br />
</tr>
<tr>
<td><img src="/sites/1676/commentaires/images/comment.gif" alt="Réagir" width="20" height="19" /></td>
<td><a href="liste_com.cfm?COM_ID=#Qsujets.SUJ_ID#"></a><a href="/index.cfm/2,0,1676,9914,2831,0,html?SUJ_ID=#Qsujets.SUJ_ID#">Réagir à cet article</a></td>
</tr>
</table>
______________________________________</div>
</li></ul>
</cfoutput>
</body>
</html>
<cfquery name="Qsujets" datasource="Modules_Web">
SELECT *
FROM dbo.Sujet
ORDER BY SUJ_ID
DESC
</cfquery>
<cfquery name="Qcommentaire" datasource="Modules_Web">
SELECT *
FROM dbo.Commentaire
</cfquery>
<html>
<head>
<title>Liste des sujets</title>
<link href="/sites/1676/commentaires/CSS/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Liste des articles </h1>
<br />
<cfoutput query="Qsujets">
<ul><li>
<span class="sujets">#Qsujets.SUJ_Nom#</span><br />
<span class="auteur">#Qsujets.SUJ_Auteur#</span><br />
<span class="description">#Qsujets.SUJ_Description#</span><br />
<div id="bloc_sujet">
<table>
<tr>
<td><img src="/sites/1676/commentaires/images/oeil.gif" alt="Lire les réactions " width="20" height="20" /></td>
<td><a href="/index.cfm/2,0,1676,9914,2832,0,html?COM_ID=#Qsujets.SUJ_ID#">Lire les réactions à cet article </a> (#Qcommentaire.RecordCount#)</td>
<br />
</tr>
<tr>
<td><img src="/sites/1676/commentaires/images/comment.gif" alt="Réagir" width="20" height="19" /></td>
<td><a href="liste_com.cfm?COM_ID=#Qsujets.SUJ_ID#"></a><a href="/index.cfm/2,0,1676,9914,2831,0,html?SUJ_ID=#Qsujets.SUJ_ID#">Réagir à cet article</a></td>
</tr>
</table>
______________________________________</div>
</li></ul>
</cfoutput>
</body>
</html>
TOPICS
Getting started
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/display-record-count-in-a-comments-application/m-p/232000#M20544
Jun 11, 2008
Jun 11, 2008
Copy link to clipboard
Copied
something like this?:
SELECT dbo.Sujet.*, COUNT(dbo.Commentaire.*) AS commentscount
FROM dbo.Sujet LEFT JOIN dbo.Commentaire ON dbo.Sujet.SUJ_ID =
dbo.Commentaire.SUJ_ID
GROUP BY dbo.Sujet.SUJ_ID
ORDER BY dbo.Sujet.SUJ_ID DESC
i suggest you list just the necessary fields in your queries instead of
using SELECT *.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
SELECT dbo.Sujet.*, COUNT(dbo.Commentaire.*) AS commentscount
FROM dbo.Sujet LEFT JOIN dbo.Commentaire ON dbo.Sujet.SUJ_ID =
dbo.Commentaire.SUJ_ID
GROUP BY dbo.Sujet.SUJ_ID
ORDER BY dbo.Sujet.SUJ_ID DESC
i suggest you list just the necessary fields in your queries instead of
using SELECT *.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

