Code:
<?php
/* set the allowed order by columns */
$default_sort = 'LastName';
$allowed_order = array ('JoinDate', 'FirstName','LastName', 'loginDateTime');
$allowed_display = array('FirstName', 'LastName', 'PhoneNumber', 'MobileNumber', 'Email', 'City', 'State', 'JoinDate', 'MemberApproved', 'loginDateTime');
/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}
if ($_REQUEST['act'] == "del") {
$del = $_REQUEST['del'];
mysql_query("UPDATE `tblmembers` SET `status`='D' WHERE `userID`='$del'");
header('Location: '.$_SERVER["PHP_SELF"]);
}
else {
/* construct and run our query */
$query = "SELECT * FROM tblmembers WHERE `MemberApproved`='$cat' ORDER BY $order";
$result = mysql_query ($query);
/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
echo "No data to display!";
exit;
}
/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo '<script type="text/javascript">
function showForm(id) {
obj = document.getElementById(\'edit_\'+id);
if (obj.style.display == "none") {
obj.style.display = "";
}
else {
obj.style.display = "none";
}
}
</script>
';
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
/* check if the heading is in our allowed_order
* array. If it is, hyperlink it so that we can
* order by this column */
echo "<TD><b>";
if (in_array($heading, $allowed_display)) {
if (in_array ($heading, $allowed_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&cat=$cat\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
}
<td>Edit</td>
<td>Delete</td>
echo "</TR>\n";
/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD>$column</TD>
<td><a href=\"#\" onclick=\"showForm('".$column['id']."'); return false;\">Edit</a>
<div id=\"edit_".$column['id']."\" style="display: none;">
<!--status form-->
<form method=\"POST\" action=\"{$_SERVER['PHP_SELF']}\">
<input type=\"hidden\" name=\"act\" value=\"edit\">
<input type=\"hidden\" name=\"id\" value=\"".$column['id']."\">
<select name=\"status\">
<option value=\"A\">Approved</option>
<!--enter options for status menu-->
</select>
</div>
</td>
<td><a href=\"{$_SERVER['PHP_SELF']}?del=".$column['id']."&act=del\">Delete User</a></td>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
}
?>
Not sure how well this will work (or if it even will), but hope this helps nonetheless.
Bookmarks