Jump to content

PHP and XML


DrDankWD

Recommended Posts

I have pretty much no knowledge of XML, my php skills are sufficient, but nothing to brag about.

 

I have a FLV player that runs a playlist from a XML file, I would like to make the XML be populated from a mysql database, but I am not sure how to go about doing this, I tried using php in xml file with no luck. Here is the code i used:

 

<?php

$host = "localhost"; 
$user = "icommerc"; 
$pass = "********"; 
$database = "media"; 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 
?>

<xml>
<?php 
$media_query = ("SELECT * FROM media_files ORDER BY sort_order");
while ($media_results = mysql_fetch_array($media_query) { ?>

<listitem name="<?php echo $media_results['name'];?>" url="streams" thumb="<?php echo $media_results['image'];?>">
<stream name="<?php echo $media_results['file'];?>" start="0" len="-1"/>
</listitem>

<?php } ?>
<menu>
<?php 
$menu_query = ("SELECT * FROM media_files ORDER BY sort_order");
while ($menu_results = mysql_fetch_array($menu_query) { ?>
	<listitem name="<?php echo $menu_results['name'];?>"/>

<?php } ?>
</menu>
</xml>

 

Is it possible to use XML and PHP in the same file like I have above? 

 

Please don't throw rocks at me for being so stupid!  ::)

Link to comment
Share on other sites

if you have php5 then the incredibly simple SimpleXML is for you http://uk.php.net/manual/en/ref.simplexml.php.

 

If not then the DOMXML is pretty good - although you need moer understanding of OOP and the DOM for that. http://uk.php.net/manual/en/ref.domxml.php

 

Personally I don't like having php in xml files due to the problems with short tags for php, this also affects portability. Just create the xml files using php and clean them out when they are done with.

Link to comment
Share on other sites

Thanks to both of you! I have been playing around and leraning a bit more of XML.

 

Once more quick question, how would I go about including a php file in am xml file.  In php if i wanted to include a file I would just do a

 

include('filename_goes.here');

 

but I am not sure how this is done in XML.

 

Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.