-1

I write code to save data in to the database table.

I want Replace a row in a table if it exists or insert a new row in a table if the row did not already exist.

http://codex.wordpress.org/Class_Reference/wpdb

I use $wpdb->replace function and then add $wpdb->insert_id to end of code.

But when run my own wordpress plugin . only add new rows with values .Can't replace values.

 $wpdb->replace( $wpdb->prefix . 'fafa', 
   array( 
   'title' =>  trim($row->item(0)->nodeValue) ,
   'liveprice' =>  trim($row->item(2)->nodeValue)  ,
   'changing' =>   trim($row->item(4)->nodeValue)  ,
   'lowest' =>   trim($row->item(6)->nodeValue)  ,
   'topest' =>   trim($row->item(8)->nodeValue)  ,
   'time' =>   trim($row->item(10)->nodeValue)   ), 
   array( 
   '%s',
   '%s',
   '%s',
   '%s',
   '%s',
   '%s'
) );
 $wpdb->inser_Id;

table photo

table

strucher

In Following photo Now id is Unique

db

rahavard
  • 57
  • 9

1 Answers1

0

this is in your code--->>>>>>>

$wpdb->inser_Id; ***********************

it should be--->>>>>>>>

$wpdb->insert_Id;

Atif
  • 280
  • 1
  • 11