我有一个users.php
存储所有功能的文件。我想创建一个删除按钮来删除某个经理下的任何列出的员工。这是我对成员函数的看法:
public function view_team($username) {
$query = $this->db->prepare("SELECT * FROM `users` WHERE `manager`= ? ORDER BY `lastname` ASC ");
$query->bindValue(1, $username);
$i = 0;
try{
$query->execute();
foreach ($query as $row) {
$removable=$row['id'];
print $i+1 .') '.$row['lastname'].' '.$row['firstname'].', Department: '. $row['department'] .', Band: '.$row['band'].' | '; ?>
Promote <img src="img/promote.png" alt="Promote employee"> | <!-- promote user -->
Edit <img src="img/edit.png" alt="Edit employee"> | <!-- edit user -->
<a href ="#" onclick="$users->remove($removable)">
Remove <img src="img/remove.png" alt="Remove employee"></a> <!-- remove user -->
<?php print '<br>';
$i++;
}
$this->queryResult = $query->fetch();
} catch(PDOException $e){
die($e->getMessage());
}
}
这是删除功能:
public function remove($username) {
$query=$this->db->prepare("DELETE from `users` WHERE `id`=?");
$query->bindValue(1,$removable);
try{
$query->execute();
} catch (PDOException $e){
die($e->getMessage());
}
}
这就是我查看用户的方式:
<?php
$usr = $firstname ." ". $lastname;
$users->view_team($usr);
?>
我想我需要创建一个onclick()
仅在按下删除按钮时才起作用的函数。