onthespot Posted August 4, 2009 Share Posted August 4, 2009 Hey guys I have three different places on my site at present where people can comment. They enter three tables called, comments, leaguecomments and newscomments. I have a place where it displays the last 5 comments in desc order from the table comments. I am looking for it to display the last 5 comments ordered by the date from all three tables. So 5 comments that are the newest over the all three tables. <? $res=mysql_query("SELECT SUBSTRING(comment, 1, 13) as comment, touser FROM ".TBL_COMMENTS." ORDER BY commentdate DESC LIMIT 5") or die(mysql_error); while($row=mysql_fetch_assoc($res)){ $comment=$row['comment']; $touser=$row['touser']; ?> <li><a href="userprofile.php?user=<?echo $touser?>#comments"><?echo "$comment";?>...</a></li> <? } ?> That works for one table, how can I combine all three? Thanks Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 4, 2009 Share Posted August 4, 2009 I would change your table structure a bit. Instead of having 3 separate tables. Try this Categories Category, CategoryID category being News, League, etc Comments CommentID, CategoryID, UserID, Comment, CommentDate then you put all comments in that table and you just separate them by the category as you need to. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 4, 2009 Author Share Posted August 4, 2009 cheers great idea Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.