Forum Moderators: coopster
See the first example there on the link you provided:
<?php
include 'example.php';$xml = new SimpleXMLElement($xmlstr);
echo $xml->movie[0]->plot; // "So this language. It's like..."
?>
To access the plot section of the xml, you use:
$xml->movie[0]->plot;
To keep it simple, find out the values you need to store in the db in this fashion, and use the insert statement to add them to the db.
Unless I completely missed your point, this can be handled simply.
Habtom
<?php
include 'example.php';
$xml = new SimpleXMLElement($xmlstr);echo $xml->movie[0]->plot; // "So this language. It's like..."
?>
Ok, this first example looks to me like it calls the XML file using the built in PHP SimpleXML function. Then the next part prints out the XML data.
I'm guessing that SimpleXML stores each XML tag as a new array? (This is the part that I have been unsure of). So where it says <plot>So, this language. It's like...</plot> in the XML, it is now a PHP array with the name "plot" (or maybe $plot?)?
So now to enter the data into MySQL database for the subject "plot", would I use the code:
mysql_query ("INSERT INTO "name of table" (plotdata) VALUES ('plot')"); //or ('$plot') if it's stored as $plot
Is this right or am I missing something? Thank you so much for all your help as I try to learn! :) God bless!
[edited by: CWebguy at 4:59 pm (utc) on Sep. 11, 2007]
Also, if I will be using this to import data from XML to MySQL, should I create a page for this sole purpose alone with nothing but the code we just used to import the XML and just run it when I need it? (I'm not sure yet if I'll be doing it on a regular basis or not, but possibly maybe like weekly or something along those lines. But at most I will need to run it once to populate database).
Thanks!
[edited by: CWebguy at 7:17 pm (utc) on Sep. 11, 2007]