surfwtw Posted July 15, 2011 Share Posted July 15, 2011 I have my code listed below. This code is creating a list of links that will pull info from my database. I am trying to have these listed from newest entires to oldest and for some reason it isn't working. Any help would be appreciated. Thanks <?php mysql_connect('host', 'db', 'pw') or die('Error connecting to MySQL'); mysql_select_db('db'); $url = 'http://www.website.info/articledisplay.php?id='; $sqlCommand = "SELECT * FROM articles ORDER BY id DESC LIMIT 10"; // Execute the query here now $query = mysql_query($sqlCommand) or die (mysql_error()); // Output the data here using a while loop, the loop will return all members while ($row = mysql_fetch_array($query)) { $id = $row['id'] . " " . $title = $row['title'] . " " . $author = $row['author']; echo "<a href=\"{$url}{$id}{title}{author}\">{$id}</a><br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/ Share on other sites More sharing options...
AyKay47 Posted July 15, 2011 Share Posted July 15, 2011 no mysql error received? Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1242939 Share on other sites More sharing options...
surfwtw Posted July 15, 2011 Author Share Posted July 15, 2011 None at all, it just displays the data but not in the correct order. I have switched it from DESC to ASC just to test and nothing happens. Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1242944 Share on other sites More sharing options...
TeNDoLLA Posted July 15, 2011 Share Posted July 15, 2011 Are you sure that your test data is not just so similar you wont see differences? I mean there is nothing wrong in the SQL query. Should work. Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243000 Share on other sites More sharing options...
surfwtw Posted July 15, 2011 Author Share Posted July 15, 2011 Yeah, I really don't get it. I will just mess around with it until I figure it out. Maybe the link function is somehow interacting with it. I'll take it out and see what happens and then add it back. Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243183 Share on other sites More sharing options...
AyKay47 Posted July 15, 2011 Share Posted July 15, 2011 I would look at a "view source" in your browser to see what your link are showing up as.. Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243188 Share on other sites More sharing options...
jcbones Posted July 15, 2011 Share Posted July 15, 2011 Is your id column set as an integer? If the column is set as a string type, then it orders by the first character. So, all 1's (1,10,11,12, etc.) will come before the 2's (2,20,21,etc). To test this out, make you a test table, with the following id's. 1,10,2,200,50,9,18. Set the column type as varchar and run a query to order by the id desc, and asc. Now change the column type to integer. Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243239 Share on other sites More sharing options...
surfwtw Posted July 15, 2011 Author Share Posted July 15, 2011 I got it worked out. I think I must have been working with a file that when I saved I made a typo in the filename so it was never getting uploaded to the server. God I feel stupid lol. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243284 Share on other sites More sharing options...
AyKay47 Posted July 16, 2011 Share Posted July 16, 2011 I got it worked out. I think I must have been working with a file that when I saved I made a typo in the filename so it was never getting uploaded to the server. God I feel stupid lol. Thanks it's the little things in programming that cause the most confusion Quote Link to comment https://forums.phpfreaks.com/topic/242032-order-by-asc-desc-not-working-please-help/#findComment-1243499 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.