Actualización de una fila duplicada en mysql en una columna que puede agregar o cambiar su nombre
Frecuentes
Visto 67 veces
0
I am importing an xml feed into database using simple_xml_loadfile. The entries are pretty basic, but sometimes they either change or have values appended to them or both.
card name - citi thankyou card<br>
apr - 0%<br>
balance transfer - yes<br>
bullets - 0% balance transfer 18 months|2x points on all purchases|No annual fee<br>
annual fee - 0<br>
purchase apr 11.99-22.99%<p>
What I want to setup is an insert on duplicate entry so that if either the citi thankyou card changes its name to citi thankyou card - balance transfer offer or citibank thankyou card it won't add another entry, as typically everything else will stay the same, or the bullets may change.
Most of the xml fields I read from with credit cards has a unique id for the card, however this xml file does not. So if the unique id was 234567 I could check for that id and change the card name from citi thankyou card to citi thank you card
What's the best way to do this, should I manually assign a card id to each card or can a primary key with auto-increment do the trick?
Long story short I don't want it to have 1 row with citi thankyou card and another row with citibank thankyou card since they would be the same card with a simple name change.
1 Respuestas
0
A primary key and auto increment.
I'd also suggest using a select query to check for duplicates before inserting:
SELECT DISTINCT BINARY tblName
this will ignore whitespaces...
'citi thankyou card' = 'citi thank you card'
respondido 27 nov., 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php mysql xml sql-insert or haz tu propia pregunta.
so what have you tried till now - Satya
I have insert into tbl(cardname, apr, bt, bullets, annfee, purapr) values ($cardname, $apr, $bt, $bullets, $annfee, $purapr) on duplicate key update (everything but cardname) as I set cardname to unique key. The majority of the updates won't reflect the cardname, but on occasion it does, and my concern is I will end up with old cardname and new cardname, so I don't know how to distinguish old from new when the cardname changes A prime example of the card changes is going from (SM) to (TM) or (SM) to ® (Citi Thankyou Card(SM)) becomes (Citi Thankyou Card®) etc - user3040286