Answer the question
In order to leave comments, you need to log in
mysqli_affected_rows query returns 0 on DELETE?
There is a request:
DELETE FROM images WHERE id_news='$id_news' AND im_path='$image'
public function delete($query){
$result = mysqli_query($this->link, $query);
if (!$result){
$array_answer[0] = false;
$array_answer[1] = mysqli_error($this->link);
} else if(!mysqli_affected_rows($this->link)){
$array_answer[0] = false;
$array_answer[1] = "Не удалено ни одной записи!";
$array_answer[2] = mysqli_affected_rows($this->link);
} else{
$array_answer[0] = true;
}
return $array_answer;
}
$query = "DELETE FROM images WHERE id_news='$id_news' AND im_path='$image'";
$result = $this->msql->delete($query);
foreach ($remove_imgs as $image) {
$query = "DELETE FROM images WHERE id_news='$id_news' AND im_path='$image'";
$result = $this->msql->delete($query);
if(!$result[0]){
//$answer = "Часть изображений не удалена, обновите страницу|";
$answer = $result;
}
}
Answer the question
In order to leave comments, you need to log in
I got out of the situation by rebuilding the query using the IN operator
for($i = 0, $l = count($remove_imgs); $i < $l; $i++){
$remove_imgs[$i] = '\'' . $remove_imgs[$i] . '\'';
}
$string_remove_imgs = implode(',', $remove_imgs);
$query = "DELETE FROM images WHERE id_news='$id_news' AND im_path IN ($string_remove_imgs)";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question