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 ^^ Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/ 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) Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572662 Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Could you give me a Example>? Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572664 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. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572665 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.. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572670 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. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572673 Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.. ill see if it works Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572676 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 Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572681 Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 does anybody know? Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572684 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 Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572687 Share on other sites More sharing options...
mikelmao Posted June 23, 2008 Author Share Posted June 23, 2008 Is anyone availebel for helping? Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572689 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 Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572715 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. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-572806 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); ?> Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573032 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 Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573038 Share on other sites More sharing options...
fenway Posted June 24, 2008 Share Posted June 24, 2008 How about the table structure? Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573112 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); ?> Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573133 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 Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573170 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. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-573180 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. Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-574339 Share on other sites More sharing options...
fenway Posted June 25, 2008 Share Posted June 25, 2008 Drop the single quotes... Link to comment https://forums.phpfreaks.com/topic/111569-solved-small-easy-to-fix-problem-i-think-im-still-noob-sorry/#findComment-574355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.