sorting data

i doing a site were people add a comment and it gets put in a database and wen i recall the data i want to sort the data so that the highest id is first and so on down the page i have everything but the sorting part and idk how to do that this is my code so far tho:

<?php
//conects and salects database
mysql_connect ("localhost", "root", "password") or die ('I cannot connect to the database because:' .mysql_error());
mysql_select_db ("hospital");

	$pid = $_GET['id'];
	$query = "SELECT * FROM comments WHERE pid = $pid";
	$result = mysql_query($query) or die("Query failed ($query) - " . mysql_error());
while ($comments = mysql_fetch_array($result)) {
	echo "<br /> Date: ".$comments['Date_Time'].
	"<br />Comment: ".$comments['Comment'].
	"<br />";}
	
?>

You just need to add sorting rule to your SQL query, like this:
[php]$query = “SELECT * FROM comments WHERE pid = $pid ORDER BY id DESC”;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service