serio Posted October 10, 2009 Share Posted October 10, 2009 I am trying to order a list by the row "release" which is a DATE row. But when I use: $sql = "SELECT * FROM avatars ORDERBY release DESC LIMIT 0, 10"; I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home3/XXXXXXXX/public_html/XXXXXXX/avatars/index.php on line 24 i've tried everything! Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/ Share on other sites More sharing options...
corbin Posted October 10, 2009 Share Posted October 10, 2009 ORDER BY not ORDERBY Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934454 Share on other sites More sharing options...
serio Posted October 10, 2009 Author Share Posted October 10, 2009 Even with that, it still gives the error. Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934476 Share on other sites More sharing options...
PFMaBiSmAd Posted October 10, 2009 Share Posted October 10, 2009 For debugging, echo mysql_error() on the line right after your mysql_query() statement. Beyond that you would need to post your actual code. You could for example be overwriting the result resource inside of a loop, among 4-5 other possible reasons for that error. Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934481 Share on other sites More sharing options...
serio Posted October 10, 2009 Author Share Posted October 10, 2009 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release DESC LIMIT 0, 10' at line 1 <h1>Avatar Directory</h1> <br> Here you can find all of the avatars that have been released to date. You can sort them by release date or category. More functions and features will be added soon. <br> <br> Note: Avatar Information pops-up in a new window. <br> <br> <a href="">Newest</a> | <a href="">Battledome</a> | <a href="">Clickables</a> | <a href="">Items</a> | <a href="">Pets/Petpets</a> | <a href="">Other</a> | <a href="">Retired</a> | <br> <br> <? mysql_connect("localhost", "MY USER", "MYPASS"); mysql_select_db("MYDB"); ?> <? $id = $_REQUEST['id']; // Gets the id of the shop from the URL. Ex: http://localhost/lols.php?id=1337 $shop would be equal to 1337 $sql = "SELECT * FROM avatars ORDER BY release DESC LIMIT 0, 10"; $query = mysql_query($sql); echo mysql_error(); $i = 0; while($results = mysql_fetch_array($query)) { if($i == 0) { echo ""; } $desc = $results['desc']; $id = $results['id']; $category = $results['category']; $cost = $results['cost']; $name = $results['name']; $image = $results['image']; $release = $results['release']; echo "<div class='abox2'><div class='aheader2'>$name</div><div class='acontent2'><table border='0' cellpadding='5' cellspacing='1'><tr><td><a href=javascript:openpopup('/avatars/avatars.php?id=$id')><img src='$image' border='0'></a></td><td valign='top'><a href=javascript:openpopup('avatars/avatars.php?id=$id')>$name - (click here for solution)</a></td></tr></table></div></div>"; $i++; if($i == 4) { echo ""; $i = 0; } } echo ""; ?> Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934486 Share on other sites More sharing options...
serio Posted October 10, 2009 Author Share Posted October 10, 2009 Using echo error_reporting(E_ALL); the error seems to be 6135 Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934488 Share on other sites More sharing options...
corbin Posted October 10, 2009 Share Posted October 10, 2009 release is a reserved word. You'll need to either use `release` or rename the column. (I suggest renaming the column since reserved words should never be used.) Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934491 Share on other sites More sharing options...
serio Posted October 10, 2009 Author Share Posted October 10, 2009 alright, I can try that. Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934498 Share on other sites More sharing options...
serio Posted October 10, 2009 Author Share Posted October 10, 2009 It works fine Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/#findComment-934500 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.