I have this code:
$sql = "SELECT * FROM deptcomment WHERE deptPostID ='$postID' ORDER BY deptCommentRegDate ASC, deptCommentRegTime ASC LIMIT 4";
It is working but it only gets the first 4 comments of a particular post. i need this code to get the last 4 comments in ASC order. Is this possible.
Any help appreciated.
Try
$sql = "SELECT * FROM deptcomment WHERE deptPostID ='$postID' ORDER BY deptCommentRegDate ASC, deptCommentRegTime DESC LIMIT 4";
... and then run array_reverse();
on the result.
While I have you, I notice that you're constructing your query in such as way that suggests you intend on passing it on to a mysql_*
type function. Please keep in mind that these types of functions have been deprecated, and that you are advised to use a library such as PDO to communicate with the database instead.