Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. function allPaths($src, $dest, $string, $db, $distanceTable) {
  2.   global $output;
  3.   if ($src == $dest) {
  4.     array_push($output, $string);
  5.   } else {
  6.     $neighbourQuery = "select actor_id, movie_id from Acting
  7.    where movie_id in (select movie_id from Acting where actor_id = %d)
  8.    and actor_id <> %d;";
  9.     $r = dbAllTuples($db, mkSQL($neighbourQuery, $src, $src));
  10.     foreach ($r as $row) {
  11.         echo "running\n";
  12.       $neighbourActor = $row[0];
  13.       $movieID = $row[1];
  14.        echo "$neighbourActor $src\n";
  15.       if (!isset($distanceTable[$neighbourActor])) {
  16.         continue;
  17.       }  
  18.       if ($distanceTable[$neighbourActor] == $distanceTable[$src] - 1) {
  19.         //get names of the the src actor and dest actor
  20.         $nameQuery = "select name from Actor where id = %d;";
  21.  
  22.         //name of src actor
  23.         $r = dbQuery($db, mkSQL($nameQuery, $src));
  24.         $row = dbNext($r);
  25.         $srcName = $row[0];
  26.  
  27.         //name of dest actor
  28.         $r = dbQuery($db, mkSQL($nameQuery, $neighbourActor));
  29.         $row = dbNext($r);
  30.         $neighbourName = $row[0];
  31.  
  32.         $stringQuery = "select title, year from movie where id = %d;";
  33.         $s = dbQuery($db, mkSQL($stringQuery, $movieID));
  34.         $movieDetails = dbNext($s);
  35.         $movieTitle = $movieDetails[0];
  36.         $movieYear = $movieDetails[1];
  37.  
  38.         $stringToAppend = "$srcName was in $movieTitle ($movieYear) with $neighbourName;";
  39.         allPaths($neighbourActor, $dest, $string.$stringToAppend, $db, $distanceTable);
  40.       }  
  41.     }  
  42.  
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement