WordPress.org

Ready to get started?Download WordPress

Forums

Can't get wpdb->rows_affected to work right (2 posts)

  1. Scott Fennell
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to figure out how many rows were deleted. rows_affected keeps returning a value of '0', no matter how many rows are deleted:

    if(is_numeric($_POST['delete_coupons'])){
    
    		$delete_coupons = $_POST['delete_coupons'];
    		$delete_query="
    			DELETE
    			FROM ".$coupon_table."
    			ORDER BY id
    			DESC
    			LIMIT $delete_coupons
    		";
    		$wpdb->query($delete_query);
    		$rows_deleted=$wpdb->rows_affected;
    		if($rows_deleted > 0){
    			echo"You just deleted the $rows_deleted most recently created coupons!";
    		}else{
    			echo"rows_deleted:$rows_deleted <br> There was an error and the coupons could not be deleted.";
    		}
    	}else{die;}
  2. Scott Fennell
    Member
    Posted 3 years ago #

    I guess could just count the amount of rows in the table before and after, but that seems silly, no?

Topic Closed

This topic has been closed to new replies.

About this Topic