Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function allPaths($src, $dest, $string, $db, $distanceTable) {
- global $output;
- if ($src == $dest) {
- array_push($output, $string);
- } else {
- $neighbourQuery = "select actor_id, movie_id from Acting
- where movie_id in (select movie_id from Acting where actor_id = %d)
- and actor_id <> %d;";
- $r = dbAllTuples($db, mkSQL($neighbourQuery, $src, $src));
- foreach ($r as $row) {
- echo "running\n";
- $neighbourActor = $row[0];
- $movieID = $row[1];
- echo "$neighbourActor $src\n";
- if (!isset($distanceTable[$neighbourActor])) {
- continue;
- }
- if ($distanceTable[$neighbourActor] == $distanceTable[$src] - 1) {
- //get names of the the src actor and dest actor
- $nameQuery = "select name from Actor where id = %d;";
- //name of src actor
- $r = dbQuery($db, mkSQL($nameQuery, $src));
- $row = dbNext($r);
- $srcName = $row[0];
- //name of dest actor
- $r = dbQuery($db, mkSQL($nameQuery, $neighbourActor));
- $row = dbNext($r);
- $neighbourName = $row[0];
- $stringQuery = "select title, year from movie where id = %d;";
- $s = dbQuery($db, mkSQL($stringQuery, $movieID));
- $movieDetails = dbNext($s);
- $movieTitle = $movieDetails[0];
- $movieYear = $movieDetails[1];
- $stringToAppend = "$srcName was in $movieTitle ($movieYear) with $neighbourName;";
- allPaths($neighbourActor, $dest, $string.$stringToAppend, $db, $distanceTable);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement