You are here: MySQL -> XML -> MySQL « PHP SQL « IT news, forums, messages
MySQL -> XML -> MySQL

Posted by strawberry on 10/19/06 12:09

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):

Array ( [name] => TABLE1 [attributes] =>
Array ( [ID] => ID1
[FIELD1] => Value1
[FIELD2] => Value2
[FIELD3] => Value3
[FIELD4] => Value4
[FIELD5] => Value5
[FIELD6] => Value6 )
[children] =>
Array ( [0] =>
Array ( [name] => TABLE2 [attributes] =>
Array ( [ID] => ID1
[FIELD1] => Value1
[FIELD2] => Value2
[FIELD3] => Value3
[FIELD4] => Value4 ) )

[1] => Array ( [name] => TABLE1 [attributes] =>
Array ( [ID] => ID2
[FIELD1] => Value1
[FIELD2] => Value2
[FIELD3] => Value3
[FIELD4] => Value4
[FIELD5] => Value5
[FIELD6] => Value6))

[children] => TABLE2 [attributes] =>
Array ( [ID] => ID2
[FIELD1] => Value1
[FIELD2] => Value2
[FIELD3] => Value3
[FIELD4] => Value4 ) )
)

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.

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.
Because (at present) not all of the db data is contained within the XML
page, I can't simply drop the tables and recreate them each time -
well, not unless I rethink the XML page a little.

I'd appreciate any help on any aspects of this problem - correctly
traversing the array, building the statements and maintaining
integrity.

Thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация