Jump to content

Comments


onthespot

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/168847-comments/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/168847-comments/#findComment-890879
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.