在 xml 文件中回显 php 代码 [英] echo php code in xml file

查看:44
本文介绍了在 xml 文件中回显 php 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

又是一个查询.如果这太复杂了,我什至不会打扰...所以这里是查询.

its me again with yet another query.If this is going to be too complexed then i wont even bother...so heres the query.

我有这个人的头衔、艺术家、姓名存储在mysql中的奉献消息.可能这是愚蠢的..是否可以创建xml文件以从数据库中检索上述四个信息.我已经在 xml 文件中编写了以下代码,但不确定缺少什么.config.php 有数据库连接信息.

I have the title,artist,name of the person & dedication message stored in mysql.May be this is stupid..is it possible to create xml file to retrieve the above four information from the database. I have coded the below on the xml file but not sure whats missing.The config.php has database connection information.

非常感谢您的帮助!!!!新

Many thanks for your help!!!! Nev

    <?php

require("config.php");



$i=0;
$db = "SELECT * FROM songlist WHERE songtype='S' ORDER BY date_added DESC LIMIT 50";
$db = "SELECT songlist.artist, songlist.title, requestlist.name, requestlist.msg FROM songlist, requestlist WHERE requestlist.name <> '' and requestlist.songID = songlist.ID ORDER BY requestlist.t_stamp DESC LIMIT 20";
$count = 1;

    while($results = $db->row())
    {
      $count++;

      if(($count % 2)== 0)

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

<trackList>
  <track>

        <Song><?php echo $results['title']?></Song>
        <album><![CDATA[<?php echo $results['artist']; ?>]]></album>
    </track>

    </trackList>

</playlist>

<?
$i++;
}
?>

推荐答案

你还没有解释你的问题是什么?另外,我需要有关 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:

这篇关于在 xml 文件中回显 php 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆