Exemplo n.º 1
0
function loadDataFromDB($con, $movies_file_name, $commonCast_file_name, $commonGenres_file_name, $commonDirectors_file_name)
{
    global $movies;
    global $commonCast;
    global $commonGenres;
    $movies = getTop250Movies($con);
    $commonCast = getCommonCast($con);
    $commonGenres = getCommonGenres($con);
    $commonDirectors = getCommonDirectors($con);
    if (!file_exists('data')) {
        mkdir('data', 0700, true);
    }
    // save movies JSON
    $fp = fopen($movies_file_name, 'w');
    fwrite($fp, json_encode($movies));
    fclose($fp);
    // save commonCast
    $fp = fopen($commonCast_file_name, 'w');
    fwrite($fp, json_encode($commonCast));
    fclose($fp);
    // save commonGenres
    $fp = fopen($commonGenres_file_name, 'w');
    fwrite($fp, json_encode($commonGenres));
    fclose($fp);
    // save commonDirectors
    $fp = fopen($commonDirectors_file_name, 'w');
    fwrite($fp, json_encode($commonDirectors));
    fclose($fp);
}
Exemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: cristiprg
 * Date: 1/24/2016
 * Time: 1:20 AM
 */
require "include/php/mysql_connection.php";
$con = connectToMySQL();
$id = $_GET['id'];
//$result = mysql_query("SELECT * FROM `name` WHERE id='". $id ."'", $con);
// table links (link_id, movie1_id, movie2_id);
// $resultLinks = [ [1, 1, 2], [2, 2, 3], [3, 2, 4]]
$result = getTop250Movies($con);
$trimmedResult = array();
foreach ($result as $movie) {
    $trimmedResult['nodes'][] = array('name' => $movie['title'], 'group' => 1);
}
$i = 0;
foreach ($trimmedResult['nodes'] as $node) {
    if ($i != 0) {
        $trimmedResult['links'][] = array('source' => $i, 'target' => $i - 1, 'weight' => 1);
    }
    $i++;
}
/*
$array = array(
  'nodes' => array(
      array('name' => 'aaaa', 'group' => 1),
      array('name' => 'aaaa', 'group' => 1),