Page 1 of 1
Newbie question
Posted: Thu Apr 05, 2007 12:46 pm
by bebensiganteng
Hi guys please help,
How do you sort a guestbook from the earliest to the latest? because my guestbook seems sorting the input randomly
take a look at
http://www.rahmat79.com
Thanks
Posted: Thu Apr 05, 2007 12:48 pm
by RobertGonzalez
Show us the code that is building the initial sort.
Posted: Sun Apr 08, 2007 10:13 pm
by bebensiganteng
here is my code;
Code: Select all
$query = "SELECT name, comments, tanggal, email FROM guestbook";
$result = mysql_query($query, $handler);
if(!$result) {
print("<div id='alert'><p>Read Error</p></div>");
exit;
} else {
while ($row = mysql_fetch_assoc($result)) {
//Secret..
} else {
print("<div id='tamu'>
<p><img src='gambar/index/tamu.png' border='0' />
<span>".$row['name']."</span> | ".$row["tanggal"]."<br>
".$row["comments"]."
</p></div>");
}
}
mysql_close($handler);
}
and sorry for my mistakes..
Thanks
Posted: Mon Apr 09, 2007 3:10 am
by timvw
You'll need atleast an id or a datetime to track the order in which entries where added.. And then you can add a SORT BY clause using that column to your select query...
Posted: Mon Apr 09, 2007 6:41 am
by ma_be
As one of persons said you need an id,
but you may try this code:
$query = "SELECT name, comments, tanggal, email FROM guestbook ORDER BY name DESC ";
You can use anything not only name like comment tanggal....etc.
And:
DESC means down-> up.
ASC means up _> down.
I hope i works.