Jump to content

Recommended Posts

Hi.

I'm building a system for keeping track of video clips, and need to output the information from the MySQL database an XML file.

 

The structure I wanted they wanted for the XML file is something like:

 

<?xml version="1.0" encoding="UTF-8" ?>
<clips>
  <client value="Client1">
  	<clip id="394">
	<title>Title 1</title>
	<categories>Cat1,Cat2</categories>
	<video>videourl/foo1.flv</video>
	<thumbnail>thumburl/thumb1.jpg</thumbnail>
	<date>2008-03-09</date>
	<author>AuthorName</author>
</clip>
  	<clip id="395">
	<title>Title 2</title>
	<categories>Cat1,Cat2</categories>
	<video>videourl/foo2.flv</video>
	<thumbnail>thumburl/thumb2.jpg</thumbnail>
	<date>2008-03-09</date>
	<author>AuthorName</author>
</clip>
  </client>
  <client value="Client2">
  	<clip id="396">
	<title>Title 3</title>
	<categories>Cat1,Cat2</categories>
	<video>videourl/foo3.flv</video>
	<thumbnail>thumburl/thumb3.jpg</thumbnail>
	<date>2008-03-09</date>
	<author>AuthorName</author>
</clip>
  	<clip id="397">
	<title>Title 4</title>
	<categories>Cat1,Cat2</categories>
	<video>videourl/foo4.flv</video>
	<thumbnail>thumburl/thumb4.jpg</thumbnail>
	<date>2008-03-09</date>
	<author>AuthorName</author>
</clip>
  </client>
</clips>

 

Where 'client', title, video, thumbnail, date, author etc are columns in the DB. So what I need to group all the entries with the matching 'client' fields, then output the related videos as the children of that client... Does that make sense?

 

I hope someone can help me get on the right path here. I imagine it's something to do with setting up the right loop with GROUP_CONCAT or GROUP BY, but I'm a little lost as it is.

 

Thank you!

Thanks for the reply - I can see that I'd need to order by client in order to output each one in that order, however what I'm looking to do is group all the related videos under one parent node for each unique client like so:

 

<clips>
  <client value="Client1">
     <clip>
     [clipinfo]
    </clip>
     <clip>
     [clipinfo]
   </clip>
  </client>
  <client value="Client2">
     <clip>
      [clipinfo]
   </clip>
  </client>
</clips>

 

So you can see how the first Client has 2 clips, the second only has one etc.

 

I think it would need to sort through all the 'client' fields, create a parent node for each unique one, then loop through the data again and where 'client' matches the parent node, add the clip info as a child of the relevant one.

 

Thanks.

Could do or just order all clips by client ID. In a loop when the client ID changes then close the node and create a new node.

 

So your database results returned may look like

 

clipId clientId             author Title

1 1 joe xxxxxxxx

2 1 joe xxxxxxxx

3 1 joe xxxxxxxx

4 2 phil xxxxxxxx

5 2 simon xxxxxxxx

Got it all sorted thanks, if anyone else needs it:

 

<?php
$clients_query = mysql_query("SELECT client FROM clips GROUP BY client");
while($row=mysql_fetch_assoc($clients_query))
{
	$clientarray[]=$row['client'];
}
$client_num = count($clientarray);
for ($i = 0; $i <= $client_num-1; $i++)
{
	$data_query = mysql_query("SELECT * FROM clips WHERE client='".$clientarray[$i]."'");
	print "\t<client name=\"$clientarray[$i]\">\n";
	while($data=mysql_fetch_assoc($data_query))
	{
		$items .= "\t \t<clip id=\"{$data['id']}\"> \n";
		$items .= "\t \t \t<title>{$data['title']}</title> \n";
		$items .= "\t \t \t<categories>{$data['title']}</categories> \n";
		$items .= "\t \t</clip>\n";
	}
	print "\t</client>\n";
}
?>

 

And then I have it writing to an XML file from there.

 

Many thanks for the help!

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.