Hallo
ik heb een stukje sql:
<?php
$selecteer_news_sql = "
SELECT
n.titel,
n.datum,
c.naam AS auteur,
l.naam AS cat,
n.actief,
n.id AS id,
COUNT(comments.id) AS reacties
FROM
nieuws AS n,
cats AS c,
leden AS l,
comments
WHERE
n.user_id = l.id AND
n.cat = c.id
".$select_user_news."
".$zoek_sql."
".$actief_sql."
GROUP BY
(n.id)
ORDER BY
n.datum DESC,n.id DESC
LIMIT
".$limit;
?>
Hiermee haal ik dus wat gegevens uit verschillende tabellen...
Nu zit het probleem in het tellen van het aantal rijen uit de tabel reacties per nieuwsitem. Met de sql die ik nu heb geeft hij alle rijen terug... dus het aantal rijen in die tabel totaal, en ik wil per nieuwsitem.
Als ik nog comments.news_id = n.id bij zet geeft hij een error:
<?php
$selecteer_news_sql = "
SELECT
n.titel,
n.datum,
c.naam AS auteur,
l.naam AS cat,
n.actief,
n.id AS id,
COUNT(comments.id) AS reacties
FROM
nieuws AS n,
cats AS c,
leden AS l,
comments
WHERE
n.user_id = l.id AND
n.cat = c.id
comments.news_id = id
".$select_user_news."
".$zoek_sql."
".$actief_sql."
GROUP BY
(n.id)
ORDER BY
n.datum DESC,n.id DESC
LIMIT
".$limit;
?>
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'comments.news_id = id GROUP BY (n.id) ORDER BY n.datum DESC,n.i' at line 17
Ik heb al een hele tijd geprobeerd enzo... maar ik kom er niet echt uit ...
Groeten,
Arian
1.896 views