thehappyappy
06-30-2008, 08:55 PM
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 set up 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'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:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/west/public_html/search.php on line 121
Warning: implode() [function.implode]: Argument to implode must be an array. in /home/west/public_html/search.php on line 121
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/west/public_html/search.php on line 128
Line 121 is:
$results = implode(mysql_fetch_assoc(mysql_query ("SELECT COUNT(*) " . $sql_from . $sql_where . $sql_order))); and that is used to display 5 results at a time and line 128 is: the error that's shown if there was a problem with the query
echo("<p>Doh! Error performing query: " . mysql_error($result) . "</p>");
I'd be grateful if anybody could give me any help with this.
Thanks
At the moment it's set up 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'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:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/west/public_html/search.php on line 121
Warning: implode() [function.implode]: Argument to implode must be an array. in /home/west/public_html/search.php on line 121
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/west/public_html/search.php on line 128
Line 121 is:
$results = implode(mysql_fetch_assoc(mysql_query ("SELECT COUNT(*) " . $sql_from . $sql_where . $sql_order))); and that is used to display 5 results at a time and line 128 is: the error that's shown if there was a problem with the query
echo("<p>Doh! Error performing query: " . mysql_error($result) . "</p>");
I'd be grateful if anybody could give me any help with this.
Thanks