Jump to content

[SOLVED] ORDERBY date not working :/


Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/177221-solved-orderby-date-not-working/
Share on other sites

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.

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 "";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.