Support » Plugins and Hacks » Can't get wpdb->rows_affected to work right

  • Scott Fennell

    (@scofennellgmailcom)


    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;}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Can't get wpdb->rows_affected to work right’ is closed to new replies.