开发者

echo php code in xml file

开发者 https://www.devze.com 2023-03-03 06:44 出处:网络
its me again with yet another query.If this is going to be too complexed then i wont even bother...so heres the query.

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

    &l开发者_开发技巧t;?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++;
}
?>


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:


Okay, your primary problem seems this:

$db = "SELECT * ..";
$db = "SELECT song ...";

    while($results = $db->row())
    {

You are assigning a string there, and immediately afterwards try to use it as some sort of database interface. Since I have no idea what is going on in your config script, or what weird database interface you use, it's easier explained with using the outdated mysql_functions:

$result = mysql_query("SELECT songlist.artist, ... goes here");

while($results = mysql_fetch_assoc($result))
{

The mysql_query runs your SELECT statement, and only then can you iterate over the results with mysql_fetch_assoc using the $result value that you got from mysql_query.

Note that you have to decide which of your two queries to actually run here. You cannot use two SELECT queries concurrently. (Or not not in your case at least.)

0

精彩评论

暂无评论...
验证码 换一张
取 消