DamienRoche Posted December 15, 2008 Share Posted December 15, 2008 I have a table with some information in...obvioulsy. Want I want to do is present this information, one line at a time, in a particular order (by timestamp). I've searched for php while and mysql tuts but can't find what I'm looking for. Any one know how I would go about this? Something like: ->order entries by timestamp (earliest to latest) ->loop through entry ->for each entry (can't use foreach) - echo entry then <br> Any help much appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
webref.eu Posted December 15, 2008 Share Posted December 15, 2008 Some code that you can adapt: <?php include('inc-dbconnect.php'); //store the SQL query in the result variable $result = mysql_query("SELECT * FROM Reviews ORDER BY ReviewDate DESC"); if(!$result) die("Query Failed."); if(mysql_num_rows($result)) { echo ("<table border='1' cellpadding='3' cellspacing='0'>"); echo ("<tr><td>Review Id</td><td>Review Rating</td><td>Review Desc</td><td>Review Date</td></tr>"); //output as long as there are still available fields //while($row = mysql_fetch_row($result)) //associative array allows you to use field names to get results while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { /* $row[0] now contains the first column of the current row, index 1 is the second, etc. */ echo ("<tr>"); echo '<td>' . $row[ReviewId] . '</td>'; echo '<td>' . $row[ReviewRating] . '</td>'; echo '<td>' . nl2br($row[ReviewDesc]) . '</td>'; echo '<td>' . $row[ReviewDate] . '</td>'; echo ("</tr>"); } } //if no fields exist else { echo ("There is nothing in the database"); } echo ("</table>"); //echo ("Username: $username "); mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.