Title: sql update in wpdb: increment a column
Last modified: August 20, 2016

---

# sql update in wpdb: increment a column

 *  [Jonas_](https://wordpress.org/support/users/jonas_/)
 * (@jonas_)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/sql-update-in-wpdb-increment-a-column/)
 * I want to update the views only when certain things are shown… so i’ve a code
   for that.. but now to update it.. would this work???
 * `$wpdb->update( $table, array( 'views' => 'views'+1 ), array( 'id' => $new_result-
   >id ) ); ?>`
 * or how do i increment it with the wpdb syntax?
 * Thanks in advance!

Viewing 1 replies (of 1 total)

 *  [Kakoma](https://wordpress.org/support/users/kakomap/)
 * (@kakomap)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/sql-update-in-wpdb-increment-a-column/#post-2189864)
 * Jonas, you may want to consider retrieving the value of ‘views’ using a select:
   
   e.g `$view = $wpdb->get_var( $wpdb->prepare( "SELECT view FROM $table WHERE id
   ='$new_result->id';" ) );` then incrementing it `$views = $view+1;` then running
   your update above with the new value

Viewing 1 replies (of 1 total)

The topic ‘sql update in wpdb: increment a column’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Kakoma](https://wordpress.org/support/users/kakomap/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/sql-update-in-wpdb-increment-a-column/#post-2189864)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
