Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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' ) 
);
like image 613
Rishabh Avatar asked Jul 25 '26 10:07

Rishabh


1 Answers

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...

like image 146
Rishabh Avatar answered Jul 28 '26 03:07

Rishabh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!