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!!!!