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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大