doupai1876 2011-05-07 04:03
浏览 61
已采纳

在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.

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++;
}
?>
  • 写回答

2条回答 默认 最新

  • duanmu1736 2011-05-07 04:22
    关注

    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) 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!!!

    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.

    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

    Cheers

    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>     
    

    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:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?