Jump to content

ORDER BY


unplugged_web

Recommended Posts

I want to have an order by date, name, email etc on a site ,but I don't even know where to start. When somebody goes to the results page I want them to be able to click on say name and then the results are displayed in order of names.At the moment it's se tup to automatically display by date added using:

$sql_order = " ORDER BY date DESC";

but I don't know how to change this so the user can select how they're ordered.I'd be grateful if anybody could give me any pointersThanks

Link to comment
Share on other sites

I want to have an order by date, name, email etc on a site ,but I don't even know where to start. When somebody goes to the results page I want them to be able to click on say name and then the results are displayed in order of names.At the moment it's se tup to automatically display by date added using:
$sql_order = " ORDER BY date DESC";

but I don't know how to change this so the user can select how they're ordered.I'd be grateful if anybody could give me any pointersThanks

I've tried:
$sql_order = " ORDER BY '. $_GET['orderby'] . ' DESC";

$result = mysql_query ($sql_select . $sql_from . $sql_where . $sql_order . $sql_limit);

Order by: <a href='?orderby=name'>name</a> <a href='?orderby=email'>email</a>

but get an error saying:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/west/public_html/search.php on line 74
line 74 is:
$sql_order = " ORDER BY '. $_GET['orderby'] . ' DESC";

Link to comment
Share on other sites

I've tried:...but get an error saying:...line 74 is:...
You've mixed double and single quotes. Try
$sql_order = " ORDER BY ". mysql_real_escape_string($_GET['orderby']) . " DESC";

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...