php - xml parsing foreach loop + only one record inserted? -
i cant life of me figure out how code process more 1 record. code works fine, inserts first record , stops.
the feed: http://online.computicket.com/web/events/search.rss
the php:
<?php $con=mysqli_connect("localhost","vadevco_reticket","3wer5top","vadevco_reticket"); if( ! $xml = simplexml_load_file('feed.xml') ) { echo 'unable load xml file'; } else { foreach( $xml $event ) { $idrandom = rand(0,99); $title = $event->item->title; $description = $event->item->description; $link = $event->item->link; $guid = $event->item->guid; $pubdate = $event->item->pubdate; $image_t = $event->item->image_thumb; $image_l = $event->item->image_large; $displaydates = $event->item->displaydates; $sql = "insert `vadevco_reticket`.`events` (`title`, `description`, `pubdate`, `image_t`, `image_l`, `displaydates`, `id`, `event_id`) values ('$title', '$description', '$pubdate', '$image_t', '$image_l', '$displaydates','','$idrandom')"; mysqli_query($con,$sql); foreach( $event->item->showdates->showdate $eventdate ) { $date = $eventdate->date; $venue = $eventdate->venue; $complex = $eventdate->complex; $region = $eventdate->region; $costs = $eventdate->costs; $sql2 = "insert `vadevco_reticket`.`instances` (`id`, `event_id`, `date`, `venue`, `complex`, `city`, `region`, `costs`) values ('', '$idrandom', '$date', '$venue', '$complex', '$city','$region','$costs')"; mysqli_query($con,$sql2); } } } ?>
any advice on how make loop through instances of $item in feed , insert them appreciated.
thanks in advance!
you need loop through items rather xml itself:
foreach( $xml->item $event ) { $idrandom = rand(0,99); $title = $event->title; $description = $event->description; ... }
Comments
Post a Comment