kvnirvana Posted November 15, 2010 Share Posted November 15, 2010 Any idea why I cant get the order by to work? $res = mysql_query ("SELECT COUNT(*), LEFT(`comment`, 3) AS truncated from comments where navn='$rows[navn]' AND adresse='$rows[adresse]' ORDER BY time desc" ) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/ Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 The error message would probably help, since you're using an aggregate column without the GROUP BY clause. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134424 Share on other sites More sharing options...
PFMaBiSmAd Posted November 15, 2010 Share Posted November 15, 2010 It would help if you posted an example of the time column data values, the actual result, and the expected result. Just telling us that it doesn't work, doesn't convey any useful information. Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134427 Share on other sites More sharing options...
kvnirvana Posted November 15, 2010 Author Share Posted November 15, 2010 There is no error, I just can't get it to do the order by. Say i have a tabel called comments. to every comment there is a time that shows when it was posted. I want the query to show the comments ordered by the latest. At the moment it shows the last comment no matter what I do. Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134455 Share on other sites More sharing options...
BlueSkyIS Posted November 15, 2010 Share Posted November 15, 2010 if you order by time desc, you will get the last comment as it has the latest time. Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134475 Share on other sites More sharing options...
kvnirvana Posted November 15, 2010 Author Share Posted November 15, 2010 Doesn't matter I fixed it, but thanks anyway :=) Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134485 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 Then post what you did to fix it so that others may benefit. Also, there are 4 additional errors on this line. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134535 Share on other sites More sharing options...
kvnirvana Posted November 15, 2010 Author Share Posted November 15, 2010 It had nothing to do with the query, it was somthing to do with where i placed the query in my full code. where do you see 4 additional errors? Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134580 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 3, really. You don't quote your array indexes, you don't wrap your interpolated variables in curly braces, and you use the 'or die' syntax, which is sloppy. Handle errors properly. Quote Link to comment https://forums.phpfreaks.com/topic/218725-order-by-wont-work/#findComment-1134594 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.