OK, I REALLY hope this makes more sense as I dont want to waste your time and you are being very generous in trying to help me fathom this.
Basically, this is a more complete version of what I am working with. I have two scripts. The first one does a switch on the booktype, and call the hardback script if it finds case as "Hardback".
<?php
require("connect.php");
$newbooks = simplexml_load_file('books.xml');
foreach ($newbooks->catalogue->xpath('//books') as $bookitem) {
$booktype = (string) $bookitem->type;
switch ($booktype) {
case "Hardback":
include 'Hardback.php';
break;
}
}
?>
<?php
$ParsedArray = array($booktitle = $bookitem->title,
$numbofpages = $bookitem->pagecount,
$Author = $bookitem->author,
$AuthorCode = $bookitem->authorrefnumber);
$writemaster = mysql_query("INSERT INTO maintable (booktitle, numberofpages, $Author) VALUES ('$booktitle', '$numbofpages','$AuthorCode')");
?>
Lets says one of the authors is called "David L Smith", and that author is the first one encountered in the loop. The problem I am having is that it appears to be accepting "David L Smith" in the query when it sets the field to populate to $author but getting stuck there. i.e. it is not populating any other authors even though there are literally dozens more. When it gets to the next "David L Smith" book, it populates that and so on... but no others.
So it seems that the SQL query is holding onto the first $author value for the entire iteration with the foreach statement. However, if I echo all the PHP values right after the parsedarray coding (and before the MySQL query), it returns all the values as required - every book for all authors and all the information required. However, it does seem that the MySQL query looks at it and says 'does this array have "David L Smith" as the author? If it doesn't, it doesnt get sent to the table". The MySQL query doesnt seem to be refreshing the $author value for the field reference.
I really don't have a clue what to do. I have encountered problems like this in the past where PHP itself didn't like a nested array in the foreach cycle and retained the original nested array for the entire sequence but the error checking I have done here suggests it is a problem with the MySQL query itself as PHP is ECHOing the correct values.
Again, thanks so much for any help you could give me. This is the last part of the task but I just cant seem to get it functional.