Could the two lines above be replaced by a $wpdb->get_col? (I'm not sure myself, just asking :))