How to Update multiple rows using $wpdb->update
-
Hi,
I have created dynamic add/remove fields in frontend post submission page. Using $wpdb->insert the system is working perfectly.I have also created a draft edit page on frontend. On this page I want these dynamic fields to get updated. I tried $wpdb->update but it only updates the last field. In short I want to update multiple rows on single click.
my code:
$project_id = $_SESSION['project_id']; global $wpdb; $reward_ids = $wpdb->get_results("SELECT * FROM wpxa_rewards WHERE project_id = $project_id"); foreach($reward_ids as $reward_id); $r_id = $reward_id->ID; $count = count( $project_reward_title ); for ( $i = 0; $i < $count; $i++ ) { global $wpdb; $wpdb->update( 'wpxa_rewards', array( 'reward_title' => "$project_reward_title[$i]", 'reward_description' => "$project_reward_description[$i]", 'reward_amount' => "$project_reward_amount[$i]", 'reward_shipping' => "$project_reward_shipping[$i]", 'est_date' => "$project_est_date[$i]" ), array( 'ID' => $r_id ), array( '%s', '%s', '%d', '%s', '%s' ), array( '%d' ) ); }
Plz help.. Thanks
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to Update multiple rows using $wpdb->update’ is closed to new replies.