Nancy Moore
Nancy Moore

Reputation: 2470

how to calculate no of rows deleted as I loop through records in php

am using the code below to loop and delete records from database. Please i will like to count the number of rows deleted as the code loops. any idea will be appreciated

$post_ids = intval($_POST['post_id']);

foreach($post_ids as $id){
    // Delete record
// I will sanitize for sql injection attack later
    $query = "DELETE FROM posts WHERE id=".$id;
    mysqli_query($con,$query);
}

Upvotes: 0

Views: 230

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76639

just delete them all at once and then call $deleted = mysqli_affected_rows($con);

see the documentation.

Upvotes: 1

Related Questions