Jump to content

[SOLVED] Ordering by DESC and ASC help!


serio

Recommended Posts

Let's say I wanted the user to be able to choose ASC or DESC

 

Could i do this with this code?

 

<?

$sort = $_REQUEST['sort']; // 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 rdate";

$query = mysql_query($sql);
echo error_reporting(E_ALL);
$i = 0;
if($sort) == "ASC" {
	$sql .= " ASC LIMIT 0, 10";
	} else {
		$sql .= " DESC LIMIT 0, 10";
	}
}
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['rdate'];
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 "";
?>

 

i've never done this before and I know the "=" or "==" on line 25 gives an error. :P

 

but if i wanted it to be like

index.php?page=avatars/index&=sort=ASC

 

it would display ASC and if it was DESC it would display DESC :D

Link to comment
Share on other sites

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.