Jump to content

Error in nesting my news feed


barniegilly

Recommended Posts

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','gilly@rackfield.co.uk',$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
Share on other sites

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','gilly@rackfield.co.uk',$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.