something like this should work:
PHP Code:
<?php
/**** NOT TESTED ****/
$insertcount = $_POST["newcount"];
$insertquote = $_POST["iquote"];
$insertref = $_POST["iref"];
$file = '../sidebar.xml';
$xml = simplexml_load_file($file);
/************************************************
I assume "newcount" is the id for the new entry?
is this submitted by the user?
if so, it could be better handled by PHP to avoid
duplicate ID's:
// find the last entry
// (assuming entries are all in numerical order,
// starting with # 1)
$last = count(xml->myquote);
// assign next entry number
$insertcount = $last + 1;
************************************************/
// this line assumes <sidebar> is your xml root
// add a new <myquote> entry
$newItem = $xml->addChild('myquote');
// add a new <id> to the new <myquote>
$newItem->addChild('id', $insertcount);
// add a new <thequote>
$newItem->addChild('thequote', $insertquote);
// add a new <reference>
$newItem->addChild('reference', $insertref);
// convert the $xml object to an xml string
// and save it to the sidebar.xml file
$xml = $xml->asXML($file);
?>
Edit:
Basic reading of your xml file (also not tested, but I use this method often):
PHP Code:
<?php
$file = '../sidebar.xml';
$xml = simplexml_load_file($file);
foreach($xml->children() as $myquote){
echo '
<hr>
id: '.$myquote->id.'<br>
the quote: '.$myquote->thequote.'<br>
reference: '.$myquote->reference;
}
/****************************************
if you wanted to list the entries in reverse order (e.g.,
most recent first), you could use this instead:
$i = count($xml->myquote)-1;
for($x=$i;$x>=0;$x--){
echo '
<hr>
id: '.$myquote[$x]->id.'<br>
the quote: '.$myquote[$x]->thequote.'<br>
reference: '.$myquote[$x]->reference;
}
// ! EDIT: fixed index references !
****************************************/
?>
Edit:
Quote:
Originally Posted by I am Abby
//ok this is where I get lost...I need to put each of the elements of the array
No, you don't - I think that's where your confusion is. simplexml_load_file() already put everything into a simplexml object (not an array, but imagine it like an array). Nothing more to set up. You can just start using it, as in my example above.