|
Posted by Captain Paralytic on 10/19/06 12:33
strawberry wrote:
> I'm trying to go back and forth between a db and XML pages that filter
> db data.
> I have a multidimensional array (parsed from XML) like this
> (simplified):
blah, blah, blah snipped
> So now I'd like to walk through the array and build MySQL statements of
> the type:
>
> "INSERT INTO TABLE1 (ID,PARENT,FIELD1,FIELD2,etc.) VALUES
> (ID1,Parent,Value1,Value2,etc.)"
>
> or
>
> "UPDATE TABLE1 SET (PARENT,FIELD1,FIELD2,etc.) =
> (Parent,Value1,Value2,etc) WHERE ID = ID1"
>
> depending on whether or not the ID exists.
Use INSERT ... ON DUPLICATE KEY UPDATE to solve this in one hit (or
possibly REPLACE INTO)
> Using array_walk_recursive() I can successfully traverse the array, but
> I'm still struggling to build the appropriate queries.
> Also, I haven't thought through what happens when items originally
> selected from the database are subsequently deleted from the XML prior
> to constructing the array.
Instead of completely deleting from the XML, can you either:
1) leave the ID in and delete everything else
or
2) leave the ID in and add a DELETE instruction
In either case, examining the node should give you the hint required to
create a DELETE FROM query instead of one of the other ones.
Regards
Paul
Navigation:
[Reply to this message]
|