Location: PHPKode > projects > PHP Media Manager with IMDB > movie_group.php
<?php

// This script currently only supports grouping files that are split using cd# format. Not tested with more than one CD in the title.

include 'config.php';

$matching = "[cD][dD].";

// select all files that have the trigger string(s) in them
$results = mysql_query("
SELECT `filename`,id
FROM `movie_scanresults`
WHERE `filename` like '%cd%'
");

while($row = mysql_fetch_assoc($results))
{
// split the files around the string
	list($pre_cd, $post_cd) = split($matching, $row[filename]);
// now see if the first section of the file matches any other, excluding already-matched files and the parent
	$sql = "select id,filename from movie_scanresults where filename like '%".$pre_cd."%' and id != ".$row[id]." and id not in (select parent_id from movie_matches where child_id = ".$row[id].") and id not in (select child_id from movie_matches where parent_id = ".$row[id].")  ";
	$match = mysql_query($sql);
	if (mysql_affected_rows() >= 1)
		{
		while ($matches = mysql_fetch_assoc($match))
			{
			echo $row[filename]." ::matches:: ".$matches[filename]."<br />";
// insert a row into the matches table giving the parent and child ids
			$update_matches_sql = "insert into movie_matches (parent_id,child_id) values (".$row[id].",".$matches[id].")";
			mysql_query($update_matches_sql);
			};
		};
};
?>
Return current item: PHP Media Manager with IMDB