I a table that I have added the function to be able to sort, it works, but it is coming up with an errors:
Notice: Undefined index: sort in C:\wamp\www\test stuff\test.php on line 25
Notice: Undefined index: sort in C:\wamp\www\test stuff\test.php on line 28
Notice: Undefined index: sort in C:\wamp\www\test stuff\test.php on line 31
Notice: Undefined index: sort in C:\wamp\www\test stuff\test.php on line 34
Notice: Undefined index: sort in C:\wamp\www\test stuff\test.php on line 37
I am stumped, I have looked all over, but I can't figure out what the problem is. Any help would be apreciated.
Thanks,
ADM
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
if($_GET['sort'] == "FNAME"){
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY FNAME";
}
elseif($_GET['sort'] == "LNAME"){
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY employees.LNAME ASC";
}
elseif($_GET['sort'] == "TITLE"){
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY employees.TITLE ASC";
}
elseif($_GET['sort'] == "NAME"){
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY departments.NAME ASC";
}
elseif($_GET['sort'] == "PHONE"){
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY employees.PHONE ASC";
}
// Default sql if no parameters given
else {
$query = "SELECT * FROM departments LEFT JOIN (employees) ON (departments.ID=employees.DEPARTMENTID) ORDER BY employees.LNAME ASC";
};
$result = mysql_query($query) or die(mysql_error());
echo '<table border="1">
<tr>
<td><a href="test.php?sort=FNAME">First Name</a></td>
<td><a href="test.php?sort=LNAME">Last Name</a></td>
<td><a href="test.php?sort=TITLE">Title</a></td>
<td><a href="test.php?sort=NAME">Department</a></td>
<td><a href="test.php?sort=PHONE">Phone</a></td>
</tr>';
while($row = mysql_fetch_array($result))
{
if($row['LNAME'])
{
echo "<tr>";
echo "<td>".$row['FNAME']."</td>";
echo "<td>".$row['LNAME']."</td>";
echo "<td>".$row['TITLE']."</td>";
echo "<td>".$row['NAME']."</td>";
echo "<td>".$row['PHONE']."</td>";
echo "</tr>";
}
}
echo "</table>";
mysql_close($con);
?>