mikelmao Posted June 23, 2008 Share Posted June 23, 2008 Hello... Well im still 13 and learning PHP.. And i need some help with a easy to fix problem.. Well i wana Order my News From Newest to lowest.. I number my news as id's I guess i have to ORDER BY but How?? Thanks ^^ Quote Link to comment Share on other sites More sharing options...
sasa Posted June 23, 2008 Share Posted June 23, 2008 order by id desc (on end of query string) Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Could you give me a Example>? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 SELECT * FROM news WHERE news_id=$id ORDER BY id DESC; Something like that. Obviously use your own query. Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Wtf i dont get it ^^ what do u mean with id DESC ? i know what DESC is.. Im not that noob.. Quote Link to comment Share on other sites More sharing options...
trq Posted June 23, 2008 Share Posted June 23, 2008 You need to pick a field to order by. eg; ORDER BY <fldname> The examples posted above are odering by a field named id, though its probably best to order by a date or timestamp type of field. Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.. ill see if it works Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Well it works but the newst post goes last.. How do i do get the newest post on top Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 does anybody know? Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Please help me people at PHP Freaks Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Is anyone availebel for helping? Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 23, 2008 Share Posted June 23, 2008 sort it ascending SELECT * FROM news WHERE news_id=$id ORDER BY id ASC; also in many forums multiposting like that is frowned upon edit: that was just using logic, I have no idea if it actually works or not, if am a complete noob at sql, starting trying it yesterday edit2: can you post your entire php code though as i think I am trying to do the same thing as you, or similar Quote Link to comment Share on other sites More sharing options...
fenway Posted June 24, 2008 Share Posted June 24, 2008 Yes, indeed it is... you won't get any help that way. Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 24, 2008 Author Share Posted June 24, 2008 include "connect.php"; $news = mysql_query("SELECT * FROM rs"); if(mysql_num_rows($news) > 0) { while($n = mysql_fetch_array($news)) { print "<dt><span class='newsdate'>" . $n['date'] . "</span>" . $n['titel'] . "</dt>"; print "<dd> <table width='100%'><tr> <td style='text-align: justify; vertical-align: top;'>". nl2br($n['news']) ."</td> <td style='padding-left: 1em; text-align: right; vertical-align: top;'> </td></tr></table>"; } } else { echo "ther is no news"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 24, 2008 Author Share Posted June 24, 2008 I forgot to post the first <? lol Sorry bbut its ther Quote Link to comment Share on other sites More sharing options...
fenway Posted June 24, 2008 Share Posted June 24, 2008 How about the table structure? Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 24, 2008 Share Posted June 24, 2008 Try this <?php include "connect.php"; $news = mysql_query("SELECT * FROM rs ORDER BY id ASC"); if(mysql_num_rows($news) > 0) { while($n = mysql_fetch_array($news)) { print "<dt><span class='newsdate'>" . $n['date'] . "</span>" . $n['titel'] . "</dt>"; print "<dd> <table width='100%'><tr> <td style='text-align: justify; vertical-align: top;'>". nl2br($n['news']) ."</td> <td style='padding-left: 1em; text-align: right; vertical-align: top;'> </td></tr></table>"; } } else { echo "There is no news at the moment."; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
mikelmao Posted June 24, 2008 Author Share Posted June 24, 2008 Try this <?php include "connect.php"; $news = mysql_query("SELECT * FROM rs ORDER BY id ASC"); if(mysql_num_rows($news) > 0) { while($n = mysql_fetch_array($news)) { print "<dt><span class='newsdate'>" . $n['date'] . "</span>" . $n['titel'] . "</dt>"; print "<dd> <table width='100%'><tr> <td style='text-align: justify; vertical-align: top;'>". nl2br($n['news']) ."</td> <td style='padding-left: 1em; text-align: right; vertical-align: top;'> </td></tr></table>"; } } else { echo "There is no news at the moment."; } mysql_close($con); ?> Tryed it but the newest post is still as last Quote Link to comment Share on other sites More sharing options...
trq Posted June 24, 2008 Share Posted June 24, 2008 Change the query to order by descending then. $news = mysql_query("SELECT * FROM rs ORDER BY id DESC"); It helps if you attempt to learn from peoples replies. Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted June 25, 2008 Share Posted June 25, 2008 similar problem what would be the correct way of doing this? $result = mysql_query('SELECT * FROM `madnessred_sites` ORDER BY '$sort' '$order' '); edit: answere $result = mysql_query("SELECT * FROM `madnessred_sites` ORDER BY '$sort' '$order' "); Also I found out what wrong with the code we gave lmao, ASC isn't right for ascending. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 25, 2008 Share Posted June 25, 2008 Drop the single quotes... 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.