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
https://forums.phpfreaks.com/topic/177232-solved-ordering-by-desc-and-asc-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.