Results 1 to 15 of 15

Thread: copy xml data using php

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: copy xml data using php

    Quote Originally Posted by maki
    That's the code i am using

    Code:
    if( !in_array( $_POST['cid'], $existing_courses)){ 
    copy_course($FILE_LIB_XML, $FILE_ARCHIVE_XML, $FILE_USERS_XML, $cid );
    And here is how i used your code to replace the above

    Code:
    $existing_courses = get_infos($FILE_ARCHIVE_XML, $cid); 
    if(!$existing_courses) 
      echo 'there was no data in that xml file'; 
    else{ 
    copy_course($FILE_LIB_XML, $FILE_ARCHIVE_XML, $FILE_USERS_XML, $cid );}
    I can not understant why the archive.xml is being updaded and still the php returns the warning which disapears when i refresh the page

    Thanks
    no, you're doing that wrong. you are supposed to be using is_array inside your function and not calling foreach() if the $cnt variable is NOT an array. your function should be structured like this (of course, the "blah"s are simply filler that you must replace real code with -- this just gives you the general idea):
    PHP Code:
    function get_infos($xml$id){ //<-- start function
      //blah blah
      
    $cnt $child->childNodes;
      if(
    is_array($cnt)){ //<-- this was added
        
    foreach($cnt as $cn){
          
    //blah blah blah
        
    }
        return 
    $mtd;
      }else 
    //<-- this and the line below were also added
        
    return false;
    //<-- end function 
    then, when you are calling get_infos(), you can use the code in my first post to see if the XML file had any information in it.
    PHP Code:
    $courses getinfos($archive_xml$id);
    if(!
    $courses)
      echo 
    'no data was found in the xml file';
    else
      
    copy_course($lib_xml$archive_xml$users_xml$id); 

  2. #2

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    Re: copy xml data using php

    That worked, the warning is disapeared. But now i get multi copies of the element in the new .xml file.

    I've used your last code as seen below

    Code:
    $existing_courses=array();
    $existing_courses = get_infosa($FILE_ARCHIVE_XML, $cid);
    if(!$existing_courses){
    copy_course($FILE_LIB_XML, $FILE_ARCHIVE_XML, $FILE_USERS_XML, $cid );
    }
    If the data don't exist i want them to be copied

    i removed the $existing_courses=array() line but the same result (the$ mtd also)
    Last edited by maki; Mar 15th, 2007 at 02:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width