php - I need to reorder my results some how -


so wrote little script. problem want newest message @ bottom not @ top how need take results mysql query , reorder them before echoing them out.. help...

edit: desc correct order while loop problem.. since php runs line line

p.s. please not worry security features add in later.

<?php mysql_connect('localhost', '', ''); mysql_select_db('');  if(isset($_post['submit'])) {      date_default_timezone_set('america/new_york');      $_post['username'] = 'guest';     //$_post['message'] = "hello name guest!";      mysql_query("insert chat (username,message,date,time) values ('".$_post['username']."','".$_post['message']."','".date('n.j.o g:i:s a')."','".time()."')");  }  $result = mysql_query("select * chat order time desc limit 10");  while ($row = mysql_fetch_assoc($result)) {     $username = $row['username'];     $message = $row['message'];     $date = $row['date'];      echo "<div><b>".$username.":</b> ".$message." <i>".$date."</i></div>"; } ?>  <form method="post"> <input name="message" /> <input type="submit" name="submit" value="send"/> </form> <br /> 

you can reverse order in php first storing results , accessing them later:

<?php  $records = array(); while ($row = mysql_fetch_assoc($result)) {     $records[] = $row; }  $records = array_reverse($records);  foreach ($records $row) {     $username = $row['username'];     $message = $row['message'];     $date = $row['date'];      echo "<div><b>".$username.":</b> ".$message." <i>".$date."</i></div>"; } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -