Can anyone help?
function getPosts(){ $sql = "SELECT `Posts`.`postID` AS `ID`, `Posts`.`postTitle` AS `Title`, LEFT(`Posts`.`postBody`, 512) AS `Preview` `Posts`.`postUser` AS `User`, DATE_FORMAT(`Posts`.`postDate`, '%d/%m/%y %H:%i:%s') AS `Date`, `Comments`.`totalComments`, DATE FORMAT(`Comments`.`lastComment`, '%d/%m/%y %H:%i:%s') AS `lastComment` FROM `Posts` LEFT JOIN ( SELECT `postID`, COUNT(`commentID`) AS `totalComments`, MAX(`commentDATE`) AS `lastComment` FROM `Comments` GROUP BY `postID` ) AS `Comments` ON `Posts`.`postID` = `Comments`.`postID` ORDER BY `Posts`.`postDate` DESC"; $posts = mysql_query($sql)or die(mysql_error()); $rows = array(); while (($row = mysql_fetch_assoc($posts)) !== false){ $rows[] = array( 'ID' => $row['ID'], 'Title' => $row['Title'], 'Preview' => $row['Preview'], 'User' => $row['User'], 'Date' => $row['Date'], 'totalComments' =>($row['totalComments'] === null) ? 0 : $row['totalComments'], 'lastComment' =>($row['lastComment'] === null) ? 'never' : $row['lastComment'] ); } return $rows; }