DrDankWD Posted February 9, 2007 Share Posted February 9, 2007 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! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 9, 2007 Share Posted February 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
curtis_b Posted February 10, 2007 Share Posted February 10, 2007 yes, this type of dynamic xml output works fine, I do it all the time. before any output you should set header('Content-Type: text/xml'); Quote Link to comment Share on other sites More sharing options...
DrDankWD Posted February 10, 2007 Author Share Posted February 10, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.