How can i put the new comment on top

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

How can i put the new comment on top

Post by ScOrPi »

Hi all ,

iam making script that's contain comments

but the problem is that the new comment always add at the bottom .. how can i make it at the top

iam using this code

Code: Select all

		  while ($mem = mysql_fetch_array($re)) {
			 print "<table width=100% border=0 cellspacing=0 cellpadding=0>";
  			 print "<tr>";
    		 print "<td class=comment_bg>كتبها ". $mem['commenter']. "</td>"
			 print "</tr>";
			 print "<tr>";
			 print "<td class=comment_bg>".$mem['comment']."</td>  </tr></table><br /><br />";           
		  }
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: How can i put the new comment on top

Post by shawngoldw »

You need to use ORDER BY somefield DESC at the end of your mysql statement. The field is probably id or if you have an auto-incrementing primary field, whatever its called.

Shawn
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: How can i put the new comment on top

Post by ScOrPi »

Thank u i got it

after Query the comment i'd Query

Code: Select all

$query = "ALTER TABLE `$mem`  ORDER BY `comments` DESC";
Thanks Dude it's work !
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: How can i put the new comment on top

Post by ScOrPi »

Sorry .. But must i put it every time befor printing the tables from mysql ?
User avatar
arrielmabale
Forum Newbie
Posts: 15
Joined: Fri Aug 13, 2010 3:57 pm
Location: Dubai

Re: How can i put the new comment on top

Post by arrielmabale »

ScOrPi wrote:Sorry .. But must i put it every time befor printing the tables from mysql ?
Yes I think you have to, Or you can specify an extra field that will identify weather its a comment or not then
filter your query on display
Post Reply