Hey everyone,
If I had a restaurant review website and wanted to show all of the latest activity (constructed by 3 queries) for a chosen restaurant ordered by the date, what would be the best way to do this? Below is a watered down example of the tables in the database.
rest
rest_id
rest_name
media
media_id
media_rest_id
media_url
media_date_added
review
review_id
review_rest_id
review_name
review_author
review_date_added
comment
comment_id
comment_rest_id
comment_text
comment_author
comment_date_added
The restaurant can have photos added to it, comments made about it and reviews written about it. So right now I have three separate queries:
1) SELECT ... FROM comment WHERE comment_rest_id = 1 ORDER BY comment_date_added
2) SELECT ... FROM review WHERE review_rest_id = 1 ORDER BY review_date_added
3) SELECT ... FROM media WHERE media_rest_id = 1 ORDER BY media_date_added
I'm outputting the results in 3 FOR EACH loops but that doesn't allow me to mix the data.
I would like it to be a list that shows each activity no matter the type, just ordered by the date. But depending on the type, there is different supporting text.. Like 'click here to read review' for reviews but 'A comment was made' for comments.
For example it might be:
12/30/09 - A review has been added, click here to read it.
12/29/09 - A comment was made:
Lorem ipsum dolor sit amet....
12/28/09 - Another comment was made:
Lorem ipsum dolor sit amet...
12/17/09 - A picture of the restaraunt was added:
< img src = "blah.jpg" />
I was debating using jquery to sort DIV elements but was wondering if there's another way with PHP / MySQL to do this?
Hopefully my description makes sense 🙂 Thanks anyone for any help on this...!