vendredi 19 décembre 2014

MYSQL Query that get different values using a condition

i was looking for something like this:



  • forum_reply (id, Text, Data, Post, User)

  • forum_post (id, Title, Text, Section, Data, User)


Post, User and Section are foreign keys.


I would show all the posts, of the section that i'm in (i'll use a WHERE Section = '".$_GET['section']."' , i'm working with PHP), order by the data, but:



  • If the post hasen't got replys, order THAT post using data of the post

  • If the post has more then 0 replys, order THAT post using data of the LAST reply


My final result would be a table that have all the posts rows order by the data that i specified first. Like this:



  • POST 1 | 0 Reply | Data of post: 19/12/2014 13:00 -> Take Data of the post

  • POST 2 | Reply > 0, Data of the last reply: 19/12/2014 14:00 -> Take Data of the last reply

  • ecc..


After that, display all such as:



  • POST 2 (19/12/2014 14:00)

  • POST 1 (19/12/2014 13:00)


I really can't made that; really need you help! Thanks very much.


Aucun commentaire:

Enregistrer un commentaire