mikeybk9 Posted March 27, 2008 Share Posted March 27, 2008 Howdy... I only know basic PHP and I'm working with a database for the first time now. I've made a page that can be updated using a form and i've got it all working perfect EXCEPT that I want the new entries to appear at the TOP, not at the BOTTOM. http://www.back9media.com.au/testing/bgr/php/latestnews.php I've used phpMyAdmin to set up the table and was wondering if there is a function in there? Cheers Mikey Quote Link to comment https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/ Share on other sites More sharing options...
tippy_102 Posted March 28, 2008 Share Posted March 28, 2008 That can be accomplished using ORDER BY in your mysql query if you are storing the date entered. Post you code so we can look. Quote Link to comment https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/#findComment-502753 Share on other sites More sharing options...
mikeybk9 Posted March 28, 2008 Author Share Posted March 28, 2008 I assume this is the bit of the code that needs the "order by" in it... <? echo "<div align=center><img src=/images/".$rows['thephoto'] ." width=400> <div /><br>"; echo "<div align=left>".$rows['thetext']."<div />"; // <--- THIS IS THE BIT THAT I WANT ORDERED DIFFERENTLY ?> After doing my own research, this bit might be usefull too... // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> Quote Link to comment https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/#findComment-502887 Share on other sites More sharing options...
BillyJim Posted March 28, 2008 Share Posted March 28, 2008 $sql="SELECT * FROM $tbl_name ORDER BY COLUMN ASC/DESC"; // depending if you want it asc or desc. Quote Link to comment https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/#findComment-502890 Share on other sites More sharing options...
mikeybk9 Posted March 28, 2008 Author Share Posted March 28, 2008 Found an article here: http://www.w3schools.com/php/php_mysql_order_by.asp It explained what I needed to know about "ORDER BY"... Original code... $sql="SELECT * FROM $tbl_name"; New code that does the job... (Note: I made a new field in my table called "id" which auto incraments to help) $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/98111-ascending-and-decending-argh/#findComment-502891 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.