Rishabh Rishabh - 7 months ago 10
SQL Question

Update wordpress database table with multiple where clauses

I am trying to update one row of database with multiple where clause but its not working. here is my code...

$wpdb->update(
'wp_cf_form_entry_values',
array(
'value' => 'example', // string
),
array( 'entry_id' => '$entryid' AND 'slug' => 'code' ),
array(
'%s', // value1
),
array( '%d', '%s' )
);

Answer

Ok I got my solution earlier. SO now I am posting it for future viewers. The problem was in 6th line.

6th line

array( 'entry_id' => '$entryid' AND 'slug' => 'code' ), 

I make below changes in 6th line...

array( 'entry_id' => $entryid, 'slug' => 'registration'), 

Now my whole update query with 2 where clause looks like below ..

$wpdb->update( 
 'wp_cf_form_entry_values', 
  array( 
    'value' => $regcode  //entering data in value field
  ), 
  array( 'entry_id' => $entryid, 'slug' => 'registration'), //two where  clause
array( 
    '%s'     //specifying which type of value entering in table
  ), 
array('%d', '%s' ) //specifying which type of value using in where cluase

);

I am also wonder even after two days why I didn't get the answer of a simple question from here. It was just a simple update query and no one knows or they didn't want to reply...

Comments