如何将两个图像取消链接在一起?

klsxnrf1  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(413)

在这个函数下面,我取消了一个图像的链接。现在我想在这个函数中取消一个图像的链接,比如“imagetwo”。
如何在这个函数中为unlink imagetwo编写代码?

public function nameDeleteById($data){

    $delete_id = $data['delete_id'];

    $stmt = $this->pdo->prepare("SELECT * FROM name WHERE id=:delete_id");
    $stmt->bindparam(":delete_id", $delete_id);
    $stmt->execute();

    if ($stmt) {
        while ($delimg=$stmt->fetch(PDO::FETCH_ASSOC)) {
            $dellink=$delimg['image'];
            unlink($dellink);
        }
    }
    $stmt=$this->pdo->prepare("DELETE FROM name WHERE id=:delete_id");
    $stmt->bindparam(":delete_id", $delete_id);
    $stmt->execute();
    if ($stmt) {
        $msg = 'Name Deleted Secessfully';
        return $msg;
    } else {
        $msg = 'Name Not Deleted Secessfully';
        return $msg;
    }
}
dauxcl2d

dauxcl2d1#

你的问题不清楚,什么 imagetwo 正是这样。我想这是报纸上的另一个专栏 name 表(?)。如果是这样的话,你可以像这样增强你的功能:

public function nameDeleteById($data){

    $delete_id = $data['delete_id'];

    $stmt = $this->pdo->prepare("SELECT * FROM name WHERE id=:delete_id");
    $stmt->bindparam(":delete_id", $delete_id);
    $stmt->execute();

    if ($stmt) {
        while ($delimg=$stmt->fetch(PDO::FETCH_ASSOC)) {
            unlink($delimg['image']);
            unlink($delimg['imagetwo']);
        }
    }
    $stmt=$this->pdo->prepare("DELETE FROM name WHERE id=:delete_id");
    $stmt->bindparam(":delete_id", $delete_id);
    $stmt->execute();
    if ($stmt) {
        $msg = 'Name Deleted Successfully';
        return $msg;
    } else {
        $msg = 'Name Not Deleted Successfully';
        return $msg;
    }
}

相关问题