English 中文(简体)
php代码
原标题:php code to return xml
  • 时间:2010-05-26 12:37:28
  •  标签:
  • php
  • xml

如果有问题,需要你们的帮助。

I have a database created for a game called gamesleaderboard and the fields are id, player_name, score, leveltime. and my task is after getting the score, i have to insert it to a database and sort the dbase accordingly. after sorting, the code will return an xml in the following structure:

Ahmad100080 Basel95090 Samer920100 Seyd900110 Ahmad100080 Basel95090 Samer920100 Seyd900110 Ahmad100080 Basel95090

plz告诉我,必须详细说明如何做到这一点。

问题回答

在大多数简单化术语中,这里没有什么特别的,你可以以同样的方式输出XML,在PHP中输出超文本,

也可以使用DOMDocument。 http://php.net/manual/en/book.simplexml.php rel=“nofollow noreferer”>SimpleXML 至输出XML,这是一个比较复杂但比较好的做法。 例如,利用MySQL

Don tabe在XML文件制作前寄出正确的Content-Type

如果你对XMLI非常新,将高度建议http://de2.php.net/manual/en/book.simplexml.php” rel=“nofollow noreferer” 简单的XML,因为它足以满足大部分需求。 利用“echo”和“strings”创建XML,不仅是一种恶毒的方案拟订技术。

使用简单的XML 你可以很容易地增加新节点,增加儿童节点和属性。 如果你能够开始阅读PHP docs,就在 go角寻求简单的XML辅导。 或请你在此提问。

$query=mysql_query("Select * from gamesleaderboard ");

$number=mysql_num_rows($query);

if ($query==0)
{
echo "0 rows Affected"; 

}

$doc= new DOMDocument();
$doc->formatOutput=true;

$root= $doc->createElement("Games");
$doc->appendChild($root);

for ($i=0; $i<$number; $i++){

    $row=mysql_fetch_array($qex);

    $node=$doc->createElement("user");
    $pn=$doc->createElement("player_name");
    $pn->appendChild($doc->createTextNode($row["player_name"]));
    $node->appendChild($pn);

    $sc=$doc->createElement("score");
    $sc->appendChild($doc->createTextNode($row["score"]));
    $node->appendChild($sc);

    $root->appendChild($node);
}


echo $doc->saveXML();

这将显示你想要的答案。 我刚刚对此进行了测试。 当你在此问这个问题时,我很可能在中学。 无论如何,它会帮助别人。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签