barniegilly Posted April 16, 2012 Share Posted April 16, 2012 I am working on a feed but am getting the nesting wrong, the </event> is appearing at the end of the whole feed and not at the end of the particular event. Here is a link to the feed http://www.horseeventsuk.com/events-feed-test.php and my code is ?> <?php :'( $output_as_html=false; if ($output_as_html) echo '<html><head><title>Events Feed</title></head><body><h1>Events Feed</h1>'; $xml='<events>'; $sql="SELECT * FROM `events` WHERE event_status='live' ORDER BY event_created DESC LIMIT 3;"; $xml.='<event>'; $result=mysql_query($sql); if ($result) { while ($row=mysql_fetch_array($result)) { $event_id=$row['event_id']; $venue_id=$row['ven_id']; $county_id=FindVenueCountyId($venue_id); //print("Found event ".$event_id.'<br />'); $xml.=EchoRowItem($row,'title',$output_as_html); //$xml.=EchoRowItem($row,'description',$output_as_html,'event_details'); $xml.=EchoTag('contact_email','[email protected]',$output_as_html); $xml.=EchoTag('county',FindVenueCountyName($venue_id),$output_as_html); $xml.=EchoTag('postcode',FindVenuePostcode($venue_id),$output_as_html); $xml.=EchoTag('website_address',BuildEventURL($event_id,$county_id),$output_as_html); $xml.=EchoRowItem($row,'startdate',$output_as_html); $xml.=EchoTag('category','Animals, Convservation',$output_as_html); $xml.=EchoTag('category','Sport',$output_as_html); $xml.=EchoTag('category','Exhibitions, Shows',$output_as_html); } } $xml.='</event>'; $xml.='</events>'; if ($output_as_html) echo '</body></html>'; else { // serve the xml file header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo $xml; } exit; 18084_.php Link to comment https://forums.phpfreaks.com/topic/261041-error-in-nesting-my-news-feed/ Share on other sites More sharing options...
Jessica Posted April 16, 2012 Share Posted April 16, 2012 Move the $xml.='</event>'; line inside the loop. Link to comment https://forums.phpfreaks.com/topic/261041-error-in-nesting-my-news-feed/#findComment-1337819 Share on other sites More sharing options...
barniegilly Posted April 16, 2012 Author Share Posted April 16, 2012 I tried that with the following code but this error XML Parsing Error: junk after document element Location: http://localhost/HorseEventsUk/events-feed2.php Line Number 2, Column 1:<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'> ^ <?php require_once("includes/connections.php"); require_once("includes/functions.php"); require_once("backend/includes/twd_functions.php"); function EchoRowItem($row,$item_name,$as_html,$row_item_name=null) { if ($row_item_name) $item_value=htmlentities($row[$row_item_name]); else $item_value=htmlentities($row[$item_name]); return EchoTag($item_name,$item_value,$as_html); } function EchoTag($item_name,$item_value,$as_html) { $s='<'.$item_name.'>'.$item_value.'</'.$item_name.'>'; if ($as_html) echo htmlentities($s).'<br />'; else return $s; } function FindVenueCountyName($venue_id) { $sql="SELECT county_id FROM `venue` WHERE ven_id='$venue_id' LIMIT 1;"; $county_id=FindMySQLResultValue($sql,'county_id'); return ucfirst(FindCountyName($county_id)); } function FindVenueCountyId($venue_id) { $sql="SELECT county_id FROM `venue` WHERE ven_id='$venue_id' LIMIT 1;"; return FindMySQLResultValue($sql,'county_id'); } function FindVenuePostcode($venue_id) { $sql="SELECT post_code FROM `venue` WHERE ven_id='$venue_id' LIMIT 1;"; return FindMySQLResultValue($sql,'post_code'); } function BuildEventURL($event_id,$county_id) { return 'http://horseeventsuk.com/event?url_countyid='.$county_id.'&url_eventid='.$event_id; } $output_as_html=false; if ($output_as_html) echo '<html><head><title>Events Feed</title></head><body><h1>Events Feed</h1>'; $xml='<events>'; $sql="SELECT * FROM `events` WHERE event_status='live' ORDER BY event_created DESC LIMIT 10;"; $result=mysql_query($sql); if ($result) { while ($row=mysql_fetch_array($result)) { $event_id=$row['event_id']; $venue_id=$row['ven_id']; $county_id=FindVenueCountyId($venue_id); //print("Found event ".$event_id.'<br />'); $xml.='<event>'; $xml.=EchoRowItem($row,'eventid',$event_id); $xml.=EchoRowItem($row,'title',$output_as_html); $xml.=EchoRowItem($row,'description',$output_as_html,'event_details'); $xml.=EchoTag('contact_email','[email protected]',$output_as_html); $xml.=EchoTag('county',FindVenueCountyName($venue_id),$output_as_html); $xml.=EchoTag('postcode',FindVenuePostcode($venue_id),$output_as_html); $xml.=EchoTag('website_address',BuildEventURL($event_id,$county_id),$output_as_html); $xml.=EchoRowItem($row,'startdate',$output_as_html); $xml.=EchoTag('category','Animals, Convservation',$output_as_html); $xml.=EchoTag('category','Sport',$output_as_html); $xml.=EchoTag('category','Exhibitions, Shows',$output_as_html); $xml.='</event>'; } } $xml.='</events>'; if ($output_as_html) echo '</body></html>'; else { // serve the xml file header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo $xml; } exit; ?> Link to comment https://forums.phpfreaks.com/topic/261041-error-in-nesting-my-news-feed/#findComment-1337822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.