= TO_DAYS(NOW()) AND (f.status IS NULL OR f.status NOT IN ('FT')) AND f.competition_id=1 ORDER BY f.kick_off ASC limit 20;"; $stmt = $mdb2->query($fixturequery); if (PEAR::isError($stmt)) { die($stmt->getMessage()); } $fixtureresult = $stmt->fetchAll(); //global variables // display document in browser as plain text // for readability purposes // create doctype $dom = new DOMDocument("1.0","UTF-8"); $dom->formatOutput = true; // display document in browser as plain text // for readability purposes //header("Content-Type: text/plain"); header("Content-type: text/xml"); // create root element $root = $dom->createElement("feed"); $dom->appendChild($root); $fixturefeed = $dom->createElement("fixtures"); $root ->appendChild($fixturefeed); //first loop gets our fixtures - sub loops will get the form for teams foreach($fixtureresult as $key => $row) { //variables $fixtureid = $row['fixtureid']; $kickoff = $row['kickoff']; $competitionname = $row['competitionname']; $competitionid = $row['competitionid']; $teamoneid = $row['teamoneid']; $teamonename = $row['teamonename']; $teamtwoid = $row['teamtwoid']; $teamtwoname = $row['teamtwoname']; $predictiontext = $row['headline'];; //create the fixtures $fixture = $dom->createElement("fixture"); $fixture->setAttribute('id',$fixtureid); $fixture->setAttribute('kick-off',$kickoff); $fixture->setAttribute('competitionid',$competitionid); $fixture->setAttribute('competitionname',$competitionname); $fixturefeed-> appendChild($fixture); $prediction = $dom->createElement("prediction"); $predictiondetail = $dom->createTextNode($predictiontext); $prediction -> appendChild($predictiondetail); $fixture -> appendChild($prediction); //head to head $headmatches = $dom->createElement("headtohead"); $headtoheadquery = "SELECT c.name AS competitionname, f.competition_id, t1.name AS teamonename, t2.name AS teamtwoname, f.kick_off, f.team_one_id, f.team_two_id,f.team_one_score,f.team_two_score FROM fixture f LEFT JOIN team t1 ON t1.team_id=f.team_one_id LEFT JOIN team t2 ON t2.team_id=f.team_two_id LEFT JOIN competition c ON c.competition_id=f.competition_id WHERE f.team_one_id IN(".$teamoneid.",".$teamtwoid.") AND f.team_two_id IN (".$teamoneid.",".$teamtwoid.") AND f.kick_off <= NOW() and f.status IN ('FT','AET','PENS') ORDER BY f.kick_off DESC LIMIT 8;"; $stmt4 = $mdb2->query($headtoheadquery); if (PEAR::isError($stmt4)) { die($stmt4->getMessage()); } while($headtoheadresult = $stmt4 -> fetchrow()) { $headmatch = $dom->createElement("match"); $headmatchteamonename = $headtoheadresult['teamonename']; $headmatchteamoneid = $headtoheadresult['team_one_id']; $headmatchteamtwoname = $headtoheadresult['teamtwoname']; $headmatchteamtwoid = $headtoheadresult['team_two_id']; $headmatchkickoff = $headtoheadresult['kick_off']; $headmatchteamonescore = $headtoheadresult['team_one_score']; $headmatchteamtwoscore = $headtoheadresult['team_two_score']; $headmatchcompetitionname = $headtoheadresult['competitionname']; $headmatchcompetitionid = $headtoheadresult['competition_id']; $headmatch->setAttribute('matchdate',$headmatchkickoff); $headmatch->setAttribute('competitionname',$headmatchcompetitionname); $headmatch->setAttribute('competitionid',$headmatchcompetitionid); $headmatch->setAttribute('homename',$headmatchteamonename); $headmatch->setAttribute('homeid',$headmatchteamoneid); $headmatch->setAttribute('homescore',$headmatchteamonescore); $headmatch->setAttribute('awayname',$headmatchteamtwoname); $headmatch->setAttribute('awayid',$headmatchteamtwoid); $headmatch->setAttribute('awayscore',$headmatchteamtwoscore); $headmatches->appendChild($headmatch); } $fixture->appendChild($headmatches); $hometeam = $dom->createElement("hometeam"); $hometeam->setAttribute('name',$teamonename); $hometeam->setAttribute('id',$teamoneid); $homematches = $dom->createElement("formmatches"); //get form for home team $formquery = "SELECT c.name AS competitionname, t1.name AS matchteamonename,t2.name AS matchteamtwoname,f.* FROM fixture f LEFT JOIN competition c ON f.competition_id=c.competition_id LEFT JOIN team t1 ON f.team_one_id=t1.team_id LEFT JOIN team t2 ON f.team_two_id=t2.team_id WHERE (team_one_id=".$teamoneid." OR team_two_id=".$teamoneid.") AND TO_DAYS(kick_off) <= TO_DAYS(NOW()) ORDER BY kick_off DESC limit 6;"; $stmt2 = $mdb2->query($formquery); if (PEAR::isError($stmt2)) { die($stmt2->getMessage()); } //$formresult = $stmt2->fetchAll(); while($formresult = $stmt2 -> fetchrow()) { $homematch = $dom->createElement("formmatch"); $matchteamonename = $formresult['matchteamonename']; $matchteamoneid = $formresult['team_one_id']; $matchteamtwoname = $formresult['matchteamtwoname']; $matchteamtwoid = $formresult['team_two_id']; $matchkickoff = $formresult['kick_off']; $matchteamonescore = $formresult['team_one_score']; $matchteamtwoscore = $formresult['team_two_score']; $matchcompetitionname = $formresult['competitionname']; $matchcompetitionid = $formresult['competition_id']; $homematch->setAttribute('matchdate',$matchkickoff); $homematch->setAttribute('competitionname',$matchcompetitionname); $homematch->setAttribute('competitionid',$matchcompetitionid); $homematch->setAttribute('homename',$matchteamonename); $homematch->setAttribute('homeid',$matchteamoneid); $homematch->setAttribute('homescore',$matchteamonescore); $homematch->setAttribute('awayname',$matchteamtwoname); $homematch->setAttribute('awayid',$matchteamtwoid); $homematch->setAttribute('awayscore',$matchteamtwoscore); $homematches->appendChild($homematch); } $hometeam->appendChild($homematches); $fixture->appendChild($hometeam); $awayteam = $dom->createElement("awayteam"); $awayteam->setAttribute('name',$teamtwoname); $awayteam->setAttribute('id',$teamtwoid); $awaymatches = $dom->createElement("formmatches"); //get form for home team $formqueryaway = "SELECT c.name AS competitionname, t1.name AS matchteamonename,t2.name AS matchteamtwoname,f.* FROM fixture f LEFT JOIN competition c ON f.competition_id=c.competition_id LEFT JOIN team t1 ON f.team_one_id=t1.team_id LEFT JOIN team t2 ON f.team_two_id=t2.team_id WHERE (team_one_id=".$teamtwoid." OR team_two_id=".$teamtwoid.") AND TO_DAYS(kick_off) <= TO_DAYS(NOW()) ORDER BY kick_off DESC limit 6;"; $stmt3 = $mdb2->query($formqueryaway); if (PEAR::isError($stmt3)) { die($stmt3->getMessage()); } while($awayformresult = $stmt3 -> fetchrow()) { $awaymatch = $dom->createElement("formmatch"); $matchteamonename = $awayformresult['matchteamonename']; $matchteamoneid = $awayformresult['team_one_id']; $matchteamtwoname = $awayformresult['matchteamtwoname']; $matchteamtwoid = $awayformresult['team_two_id']; $matchkickoff = $awayformresult['kick_off']; $matchteamonescore = $awayformresult['team_one_score']; $matchteamtwoscore = $awayformresult['team_two_score']; $matchcompetitionname = $awayformresult['competitionname']; $matchcompetitionid = $awayformresult['competition_id']; $awaymatch->setAttribute('matchdate',$matchkickoff); $awaymatch->setAttribute('competitionname',$matchcompetitionname); $awaymatch->setAttribute('competitionid',$matchcompetitionid); $awaymatch->setAttribute('homename',$matchteamonename); $awaymatch->setAttribute('homeid',$matchteamoneid); $awaymatch->setAttribute('homescore',$matchteamonescore); $awaymatch->setAttribute('awayname',$matchteamtwoname); $awaymatch->setAttribute('awayid',$matchteamtwoid); $awaymatch->setAttribute('awayscore',$matchteamtwoscore); $awaymatches->appendChild($awaymatch); } $awayteam->appendChild($awaymatches); $fixture->appendChild($awayteam); $fixture-> appendChild($awayteam); } // save and display tree echo $dom->saveXML(); */ ?>