version 1.1, 2008/02/08 22:49:12
|
version 1.3, 2010/02/23 10:18:01
|
Line 10 mysql_query ("SET NAMES 'utf8'");
|
Line 10 mysql_query ("SET NAMES 'utf8'");
|
$tour = $_GET['tour']; |
$tour = $_GET['tour']; |
|
|
|
|
if (preg_match('/\./',$tour)) |
|
{ |
|
$temp = explode('.', $tour); |
|
$fname=$temp[0];$n=$temp[1]; |
|
|
|
|
|
$sth = mysql_query( |
|
$sql="SELECT t2.Id FROM Tournaments as t1, |
|
Tournaments as t2 |
|
WHERE (t1.FileName = '$fname.txt' OR t1.FileName='$fname') |
|
AND t1.Id=t2.ParentId AND t2.Number=$n") or die(mysql_error().": $sql"); |
|
} |
|
else |
|
{ |
|
$sth=mysql_query($sql="SELECT Id FROM Tournaments WHERE FileName = '$tour.txt' OR FileName = '$tour'") or die (mysql_error().": $sql"); |
|
} |
|
|
|
$res = mysql_fetch_row ($sth); |
|
$id=$res[0]; |
|
|
|
$sth = mysql_query("SELECT * FROM Tournaments WHERE Id=$id") or die(mysql_error()); |
|
$tournament = mysql_fetch_assoc($sth); |
|
$xw = new xmlWriter(); |
$xw = new xmlWriter(); |
$xw->openMemory(); |
$xw->openMemory(); |
$xw->startDocument('1.0','utf8'); |
$xw->startDocument('1.0','utf8'); |
$xw->startElement('tournament'); |
$xw->startElement('tournament'); |
|
$tournament = getTournament($tour); |
|
|
foreach ($tournament as $key => $value) |
foreach ($tournament as $key => $value) |
{ |
{ |
$xw->writeElement ($key, $value); |
$xw->writeElement ($key, $value); |
} |
} |
|
|
$sth = mysql_query("SELECT * FROM Questions WHERE ParentId =$id"); |
printTours($tournament[Id]); |
|
|
|
printQuestions($tournament[Id]); |
|
|
|
$xw->endElement(); |
|
|
|
$xmlResult = $xw->outputMemory(true); |
|
$xmlResult = preg_replace('/\>\s*\</', ">\n<", $xmlResult); |
|
|
|
header("Content-Type: text/xml"); |
|
|
|
print $xmlResult; |
|
|
|
function printTours($tourId) { |
|
global $xw; |
|
$sth = mysql_query("SELECT * FROM Tournaments WHERE ParentId =".$tourId); |
|
|
|
while ($tour = mysql_fetch_assoc($sth) ) |
|
{ |
|
$xw->startElement('tour'); |
|
foreach ($tour as $key => $value) |
|
{ |
|
$xw->writeElement($key, $value); |
|
} |
|
$xw->endElement(); |
|
} |
|
|
|
} |
|
|
|
|
while ($question = mysql_fetch_assoc($sth) ) |
function printQuestions ($tourId) |
{ |
{ |
|
global $xw; |
|
$sth = mysql_query("SELECT * FROM Questions WHERE ParentId =".$tourId); |
|
|
|
while ($question = mysql_fetch_assoc($sth) ) |
|
{ |
$xw->startElement('question'); |
$xw->startElement('question'); |
foreach ($question as $key => $value) |
foreach ($question as $key => $value) |
{ |
{ |
$xw->writeElement($key, $value); |
$xw->writeElement($key, $value); |
} |
} |
$xw->endElement('question'); |
$xw->endElement(); |
|
} |
|
|
} |
} |
|
|
$xw->endElement('tournament'); |
|
|
|
$xmlResult = $xw->outputMemory(true); |
|
$xmlResult = preg_replace('/\>\s*\</', ">\n<", $xmlResult); |
|
|
|
header("Content-Type: text/xml"); |
function getTournament($tour) { |
|
$id = textId2Id($tour); |
|
|
|
$sth = mysql_query("SELECT * FROM Tournaments WHERE Id=$id") or die(mysql_error()); |
|
$tournament = mysql_fetch_assoc($sth); |
|
return $tournament; |
|
} |
|
|
print $xmlResult; |
function textId2Id($tour) { |
|
if (preg_match('/\./',$tour)) |
|
{ |
|
$temp = explode('.', $tour); |
|
$fname=$temp[0];$n=$temp[1]; |
|
$sth = mysql_query( |
|
$sql="SELECT t2.Id FROM Tournaments as t1, |
|
Tournaments as t2 |
|
WHERE (t1.FileName = '$fname.txt' OR t1.FileName='$fname') |
|
AND t1.Id=t2.ParentId AND t2.Number=$n") or die(mysql_error().": $sql"); |
|
} |
|
else |
|
{ |
|
$sth=mysql_query($sql="SELECT Id FROM Tournaments WHERE FileName = '$tour.txt' OR FileName = '$tour'") or die (mysql_error().": $sql"); |
|
} |
|
|
|
$res = mysql_fetch_row ($sth); |
|
$id=$res[0]; |
|
return $id; |
|
} |
|
|
?> |
?> |
|
|