Annotation of db/prgsrc/dbxml.php, revision 1.2
1.1 roma7 1: <?php
2: $hostname = "localhost";
3: $database = "chgk";
4: $username = "piataev";
5: $password = "";
6:
7: $link = mysql_connect($hostname.':'.$port, $username, $password) or die("Can't connect to database");
8: mysql_select_db($database,$link) or die ("Can't select to database");
9: mysql_query ("SET NAMES 'utf8'");
10: $tour = $_GET['tour'];
11:
12:
13: $xw = new xmlWriter();
14: $xw->openMemory();
15: $xw->startDocument('1.0','utf8');
16: $xw->startElement('tournament');
1.2 ! roma7 17: $tournament = getTournament($tour);
! 18:
1.1 roma7 19: foreach ($tournament as $key => $value)
20: {
21: $xw->writeElement ($key, $value);
22: }
23:
1.2 ! roma7 24: printTours($tournament[Id]);
! 25:
! 26: printQuestions($tournament[Id]);
! 27:
! 28: $xw->endElement('tournament');
! 29:
! 30: $xmlResult = $xw->outputMemory(true);
! 31: $xmlResult = preg_replace('/\>\s*\</', ">\n<", $xmlResult);
! 32:
! 33: header("Content-Type: text/xml");
! 34:
! 35: print $xmlResult;
! 36:
! 37: function printTours($tourId) {
! 38: global $xw;
! 39: $sth = mysql_query("SELECT * FROM Tournaments WHERE ParentId =".$tourId);
! 40:
! 41: while ($tour = mysql_fetch_assoc($sth) )
! 42: {
! 43: $xw->startElement('tour');
! 44: foreach ($tour as $key => $value)
! 45: {
! 46: $xw->writeElement($key, $value);
! 47: }
! 48: $xw->endElement('tour');
! 49: }
! 50:
! 51: }
! 52:
1.1 roma7 53:
1.2 ! roma7 54: function printQuestions ($tourId)
1.1 roma7 55: {
1.2 ! roma7 56: global $xw;
! 57: $sth = mysql_query("SELECT * FROM Questions WHERE ParentId =".$tourId);
! 58:
! 59: while ($question = mysql_fetch_assoc($sth) )
! 60: {
1.1 roma7 61: $xw->startElement('question');
62: foreach ($question as $key => $value)
63: {
64: $xw->writeElement($key, $value);
65: }
66: $xw->endElement('question');
1.2 ! roma7 67: }
! 68:
1.1 roma7 69: }
70:
71:
72:
1.2 ! roma7 73: function getTournament($tour) {
! 74: $id = textId2Id($tour);
! 75:
! 76: $sth = mysql_query("SELECT * FROM Tournaments WHERE Id=$id") or die(mysql_error());
! 77: $tournament = mysql_fetch_assoc($sth);
! 78: return $tournament;
! 79: }
1.1 roma7 80:
1.2 ! roma7 81: function textId2Id($tour) {
! 82: if (preg_match('/\./',$tour))
! 83: {
! 84: $temp = explode('.', $tour);
! 85: $fname=$temp[0];$n=$temp[1];
! 86: $sth = mysql_query(
! 87: $sql="SELECT t2.Id FROM Tournaments as t1,
! 88: Tournaments as t2
! 89: WHERE (t1.FileName = '$fname.txt' OR t1.FileName='$fname')
! 90: AND t1.Id=t2.ParentId AND t2.Number=$n") or die(mysql_error().": $sql");
! 91: }
! 92: else
! 93: {
! 94: $sth=mysql_query($sql="SELECT Id FROM Tournaments WHERE FileName = '$tour.txt' OR FileName = '$tour'") or die (mysql_error().": $sql");
! 95: }
1.1 roma7 96:
1.2 ! roma7 97: $res = mysql_fetch_row ($sth);
! 98: $id=$res[0];
! 99: return $id;
! 100: }
1.1 roma7 101:
102: ?>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>