I am trying to delete the last record in the table named \"marks\" in the database using MySql query. I was tried to do so. Also I tried on
@Abhshek's Answer is right and works for you but you can also try the following code if the id is not increment
DELETE FROM MARKS WHERE ID=(SELECT MAX(id) FROM MARKS)
This is not the best but a different solution.
DELETE FROM marks
WHERE id = (SELECT id
FROM marks
ORDER BY id DESC
LIMIT 1);
Try this:
$check = $db->prepare("SELECT `file` FROM `marks` WHERE `id` = ?");
$check->execute(array($id));
while ($checks=$check->fetchObject()) {
$unlink = unlink($uploadDir.$checks->file);
}
Where:
uploadDir is your directory;
$checks->file is your file name, saved in database;
$id is the ID row you want to delete the file;
If id
is auto-increment then you can use the following
delete from marks
order by id desc limit 1