joemorris86 Posted August 17, 2011 Share Posted August 17, 2011 Hi, I'm currently using the code below to display the results from my database, and I was wondering if theres a way I can flip the results because at the moment the newest message entered (its a chat box) is displayed at the bottom, i would prefer it at the top. <?php$host = "";$user = "";$pass = "";$db = "";$connection = mysql_connect($host,$user,$pass);if (!$connection) { die('Could not connect: ' . mysql_error()); }mysql_select_db("$db", $connection);$result = mysql_query("SELECT * FROM chat");while($row = mysql_fetch_array($result)) { echo $row['name']; echo ':'; echo $row['message']; echo '<br />'; }mysql_close($connection);?> Link to comment Share on other sites More sharing options...
JamesB Posted August 17, 2011 Share Posted August 17, 2011 you can use ORDER BY in the sql query to change the order of the rows returned, for example if you have a post_id or post_date field in the table: SELECT * FROM chat ORDER BY post_id DESC http://www.w3schools.com/php/php_mysql_order_by.asp Link to comment Share on other sites More sharing options...
joemorris86 Posted August 17, 2011 Author Share Posted August 17, 2011 awesome, thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.