Jump to content

[SOLVED] Writing an xml file with data from a mySQL table with php?


Recommended Posts

My previous post must have been too complex, here's what I need:

 

I need a PHP script that will remove the data from a mySQL table named jos_video_player and write the information to an xml file named playlist.xml

 

the fields are:

 

title

description

file

thumb

date

 

the xml file syntaxt should look like this:

 

<?xml version="1.0" encoding="utf-8"?>
<FlvPlayer>	<playlist repeat="true" shuffle="true" autoplay="true" distance="5">
	<item>
                                   <file>http://file/path/from/mysql/table/file.flv</file>
	          <thumbnail>http://file/path/from/mysql/table/file.jpg</thumbnail>
                                    <description></description>
                                     <date></date>
		</item>
</playlist>
</FlvPlayer>

 

Can anyone help me, even a link would help, I've tried several different methods to no avail.

 

Please could someone help?

 

Just use for loop to write each element yourself and then save it to an XML file.

 

Something like this:

<?php
// connect to db
$query = "SELECT * FROM jos_video_player";
$result = mysql_query($query) OR DIE("Error!!!");
// close connection to db
if ($result) {
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xml .= "<FlvPlayer>";
$xml .= '<playlist repeat="true" shuffle="true" autoplay="true" distance="5">';
while ($r = mysql_fetch_array($result)) {
	$title = $r["title"];
	$desc = $r["description"];
	$file = $r["file"];
	$thumb = $r["thumb"];
	$date = $r["date"];
	$xml .= '<item>';
	$xml .= "<file>$file</file>";
	$xml .= "<thumbnail>$thumb</thumbnail>";
	$xml .= "<description>$desc</description>";
	$xml .= "<date>$date</date>";
	$xml .= '</item>';
}
$xml .= '</playlist>';
$xml .= '</FlvPlayer>';
} else {
echo "Nothing in the db!!!";
}
?>

 

Then write $xml to playlist.xml (i don't know how to write to files, never done it before).

Will that grab every recordset in the table though? For instance, what if I have several different files that I want to load into the playlist? Basically it's for a video/picture slideshow ... I need to set this up as a cronjob to run every five minutes in case of updates.

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.