且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 xml 文件中回显 php 代码

更新时间:2023-11-24 18:54:58

你还没有解释你的问题是什么?另外,我需要有关 xml 所需格式的信息,或者您需要将哪些命令发送到数据库代码.

You haven't explained what your problem is? Also, I would need information on the format required for the xml, or what commands you'd need to send to your database code.

您似乎也有一些格式错误.我只能猜测什么会起作用,但试试这个:

It looks like you have some formatting errors as well. I can only guess at what would work, but try this:

1) 文件开头,你好像忘记了开始标签2) $i 好像没用,删掉(?)3) 您的 SQL 语句不仅没有用引号括起来,而且还需要发送到数据库代码中(完全猜测,因为我不知道您的 config.php 中的内容是 $db->query("your sql here");4) 删除:');?>5)......实际上这变得很愚蠢,我可能应该为你重写它!!!

1) At the beginning of the file, you seem to have forgotten the start tag 2) $i seems to be unused, delete it (?) 3) Your SQL statement is not only unenclosed in quotes, but would need to be sent to the database code (a complete guess since I don't know what's inside your config.php would be $db->query("your sql here"); 4) delete: '); ?> 5) ... actually this is getting silly, I should probably just rewrite it for you!!!

问题是,首先,我需要知道您是否需要使用 config.php?或者,如果我可以使用本机 php 函数进行编码.

The thing is, before anything else, I'd need to know If you NEED to use the config.php? Or if I could code using native php functions.

但这仍然充满问题(因为我不知道对 xml 的格式有什么要求)但我会试一试!所以只要告诉我你是否需要使用你的 config.php,如果不需要,我会快速编写一些代码.否则你将不得不发布 config.php 的内容

But this is still fraught with problems (since I don't know what requirements the formatting for the xml are for one) but I'll give it a go! So just tell me if you need to use your config.php or not, then if no, I'll quickly code something. Otherwise you're going to have to post the contents of config.php

干杯

好的,这是我对可行方法的***猜测:

Ok here's my best guess at what would work:

<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
    <trackList>
<?php

$DB_SERVER = "localhost";
$DB_NAME = "yourdatabasename";
$DB_USER = "yourdbuser";
$DB_PASSWORD = "yourpw";

mysql_connect($DB_SERVER, $DB_USER, $DB_PASSWORD);
mysql_select_db($DB_NAME);

$sql = "select * from songlist order by date_added desc limit 10";

$res = mysql_query($sql);

while ($result = mysql_fetch_assoc($res)){
    ?>
        <track>
            <Song><![CDATA[<?= $result['title']?]]></Song>
            <album><![CDATA[<?= $result['artist']?>]]></album>
        </track>
    <?
}
?>
</trackList>
</playlist>     

只需更改您的数据库名称、用户和密码,然后您将拥有您的 xml.但是,您可能希望将上面的相册行更改为:

Just change your database name, user and password, then you will have your xml. However, you might want to change your album line above to: