Page 1 of 1

How can i put the new comment on top

Posted: Thu Aug 12, 2010 7:49 am
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 />";           
		  }

Re: How can i put the new comment on top

Posted: Thu Aug 12, 2010 8:34 am
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

Re: How can i put the new comment on top

Posted: Thu Aug 12, 2010 9:50 am
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 !

Re: How can i put the new comment on top

Posted: Sat Aug 14, 2010 3:53 pm
by ScOrPi
Sorry .. But must i put it every time befor printing the tables from mysql ?

Re: How can i put the new comment on top

Posted: Sat Aug 14, 2010 4:22 pm
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