MySQL and sorting
Posted: Tue Dec 05, 2006 2:11 pm
Hi all. First post and I have a problem that I can't figure out.
I have an intranet that has a directory of employees. I can add, edit and delete but I need to add a sorting function.
I need to sort them by location and then possibly by lastname.
I have a form that will allow the user to choose the location, like this :
Then I have a list of the alphabet that just as plain links, like this
I am sorting by location like this :
This works for the most part. If the user selects "All" and clicks "GO", then it is passed to the URL but nothing happens.
That's one problem.
Problem 2.
For the sorting by lastname I have this
This works (I'm going to redo it so it takes into account the lastname starting with a lowercase or whatever.).
When I put them both together to sort by location, lastname or both, it doesn't work. No errors, just doesn't work.
Any ideas
Thanks in advance!!!!
I have an intranet that has a directory of employees. I can add, edit and delete but I need to add a sorting function.
I need to sort them by location and then possibly by lastname.
I have a form that will allow the user to choose the location, like this :
Code: Select all
<form action="index.php" method="get">
<select name="location">
<option value="All">All</option>
<option name="location" value="Greensboro">Greensboro</option>
<option name="location" value="Hickory">Hickory</option>
</select>
<input type="submit" name="sort" value="Go" />
</form>Code: Select all
<li><a href="index.php?alpha=A">A</a></li>
<li><a href="index.php?alpha=B">B</a></li>
<li><a href="index.php?alpha=C">C</a></li>
<li><a href="index.php?alpha=D">D</a></li>
<li><a href="index.php?alpha=E">E</a></li>Code: Select all
if(isset($sort)){
switch($location){
case ($location):
$query="SELECT * FROM contact WHERE location =" . "'" . $location . "'" . "ORDER BY lastname ASC";
break;
default:
$query="SELECT * FROM contact ORDER BY lastname ASC";
}
}That's one problem.
Problem 2.
For the sorting by lastname I have this
Code: Select all
switch ($_GET['alpha']) {
case ($_GET['alpha']):
$query = "SELECT * FROM contact WHERE lastname LIKE" . "\"" . $_GET['alpha'] . "%\"" . "ORDER BY lastname ASC";
}When I put them both together to sort by location, lastname or both, it doesn't work. No errors, just doesn't work.
Any ideas
Thanks in advance!!!!