Correct.
It’s okay to call me the village idiot, folks. I’ve been doing coding for quite awhile, but some things I haven’t experienced. This being one.
My code is as follows:
PHP:
mysql_select_db($database_JEMmanagmnt, $JEMmanagmnt);
$query_getEmployee = "SELECT empl_id, firstname, lastname, company, `position`, location, phone, email FROM employee_info";
$getEmployee = mysql_query($query_getEmployee, $JEMmanagmnt) or die(mysql_error());
$row_getEmployee = mysql_fetch_assoc($getEmployee);
$totalRows_getEmployee = mysql_num_rows($getEmployee);
<?php if ($totalRows_getEmployee == 0) { // Show if recordset empty ?>
<p class="warning">Their currently are no Employees to list</p>
<?php } // Show if recordset empty ?>
<?php if ($totalRows_getEmployee > 0) { // Show if recordset not empty ?>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr style="background: #fef3e6;">
<th style="color: #2e2203; padding-left: 10px;" scope="col"> Name </th>
<th style="color: #2e2203; padding-left: 10px;" scope="col">Company</th>
<th style="color: #2e2203; padding-left: 10px;" scope="col">Position</th>
<th style="color: #2e2203; padding-left: 10px;" scope="col">Email</th>
<th style="color: #2e2203; padding-left: 10px;" scope="col">Phone</th>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<?php $counter = 0; ?>
<?php do { ?>
<tr <?php if ($counter++ %2) {echo 'class="hilite"';} ?>>
<td style="padding-left: 10px;" scope="col"><span style="text-transform: uppercase;"><a href="employee.php?empl_id=<?php echo $row_getEmployee['empl_id']; ?>"><?php echo $row_getEmployee['firstname']; ?> <?php echo $row_getEmployee['lastname']; ?></a></span></td>
<td style="padding-left: 10px;" scope="col"><?php echo $row_getEmployee['company']; ?></td>
<td style="padding-left: 10px;" scope="col"><?php echo $row_getEmployee['position']; ?></td>
<td style="padding-left: 10px;" scope="col"><?php echo $row_getEmployee['email']; ?></td>
<td style="padding-left: 10px;" scope="col"><?php echo $row_getEmployee['phone']; ?></td>
<td scope="col"><a href="update.php?empl_id=<?php echo $row_getEmployee['empl_id']; ?>">EDIT</a></td>
<td scope="col"><a href="delete.php?empl_id=<?php echo $row_getEmployee['empl_id']; ?>">DELETE</a></td>
</tr>
<?php } while ($row_getEmployee = mysql_fetch_assoc($getEmployee)); ?>
</table>
<?php } // Show if recordset not empty ?>
Now, trying Coryboy’s method first, you’re asking me to do this:
if($_GET['sort'] == "lastname")
{
$query_getEmployee .= " SORT BY lastname DESC";
}
else if($_GET['sort'] == "company")
{
$query_getEmployee .= " SORT BY company ASC";
}
// So and so forth
mysql_select_db($database_JEMmanagmnt, $JEMmanagmnt);
$query_getEmployee = "SELECT empl_id, firstname, lastname, company, `position`, location, phone, email FROM employee_info";
$getEmployee = mysql_query($query_getEmployee, $JEMmanagmnt) or die(mysql_error());
$row_getEmployee = mysql_fetch_assoc($getEmployee);
$totalRows_getEmployee = mysql_num_rows($getEmployee);
And then you’re asking me to “Add a link by each field on your webpage. Each adds a new GET parameter called “sort”.”, which would be this, correct:
<th style="color: #2e2203; padding-left: 10px;" scope="col"><a href="list.php?sort=firstname">Name</a></th>
Please correct me if I’m wrong.
@pmw57: I read the jQuery method, and it seemed very attractive. But since the template was created in PHP (and I’ve been asked to make modifications to it), I’ll try the PHP method first, though I’d like to try the jQuery method just to see what it’s like.