Newbie question

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
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Newbie question

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Show us the code that is building the initial sort.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
ma_be
Forum Newbie
Posts: 3
Joined: Mon Apr 09, 2007 5:40 am

Post 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.
Post Reply