It's been quite a long time since I last asked a question, but I've been stumped messing with SQL in an attempt to build my own forum system.
The background of my problem is that I'm trying to create a function to display the most popular threads based on how many replies it has and how recent the latest reply was.
With some reading, I made this SQL statement.
SELECT
topics.id,
topics.authorID,
topics.lastReply
FROM
ms_topics as topics
INNER JOIN
(SELECT inTopic FROM ms_posts) as rcount
ON
rcount.inTopic = topics.id
ORDER BY
topics.lastReply DESC,
count(rcount.inTopic)
And then I use PDO's fetchAll()
function to bring the results into a variable.
$GetPopular = $db->prepare('SQL Statement Above');
$GetPopular->execute();
$Populars = $GetPopular->fetchAll();
And, in an effort to trouble shoot, I use var_dump()
on $populars
, which returns only one row from the database.
array(1) { [0]=> array(3) { ["id"]=> string(1) "4" ["authorID"]=> string(1) "1" ["lastReply"]=> string(19) "2014-06-08 19:49:50" } }
My question is basically this; why would it not be returning more than one row, and how do I make it do so?