echo 'president取得の失敗なう';
    die;
}
$president = $presidents->fetch_assoc();
// Presidentに紐付くParty情報の取得
$party = array();
$result = $Party->findBy(array('president_id' => $facebook_id));
while ($row = $result->fetch_assoc()) {
    array_push($party, $row);
}
// Presidentに紐付くPartyに紐付くFollowers情報の取得
$followers = array();
foreach ($party as $party_member) {
    $result = $Follower->findBy(array('facebook_id' => $party_member['follower_id']));
    while ($row = $result->fetch_assoc()) {
        array_push($followers, $row);
    }
}
// Presidentに紐付くPrincess情報の取得
$result = $Princess->findBy(array('facebook_id' => $president['princess_id']));
if ($result->num_rows == 0) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /princess/");
    die;
}
$princess = $result->fetch_assoc();
// followersのmoneyの合計
$total_money = 0;
foreach ($followers as $follower) {
    $total_money += $follower['money'];
}
require_once dirname(__FILE__) . '/../facebook.php';
require_once dirname(__FILE__) . "/../model/Princess.php";
// princessの構成
$fql = 'SELECT uid,pic,name FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me() )';
//echo $fql . "<br />";
$princesses = $facebook->api(array('method' => 'fql.query', 'query' => $fql));
//echo '<br />!!!!!!!!!!!!!!!!@@@@@@@@@@@@@@@@======================<br />';
// 【DB】
// 既にDBに登録されている姫:
//   情報(Scoreとか)を引っ張ってくる
// DBに未登録の姫:
//   登録する
$Model = new Princess();
for ($i = 0; $i < count($princesses); ++$i) {
    $resultRef = $Model->findBy(array('facebook_id' => $princesses[$i]['uid']));
    if ($resultRef->num_rows != 0) {
        // 登録されてる姫
        $result = $resultRef->fetch_assoc();
        //var_dump($result);
        // 姫のDB値設定
        $level = $result['level'];
        $score = $result['score'];
        $next_score = $result['next_score'];
    } else {
        // 登録されていない姫
        // DBへInsert
        $data = array();
        $data['facebook_id'] = $princesses[$i]['uid'];
        $data['name'] = $princesses[$i]['name'];
        $data['level'] = 1;
<?php

require dirname(__FILE__) . '/../../model/Princess.php';
$Model = new Princess();
if ($resultRef = $Model->findAll()) {
    $result = $resultRef->fetch_all();
    var_dump($result);
} else {
    echo "No Result";
}
if ($resultRef = $Model->findBy(array('id' => '2'))) {
    $result = $resultRef->fetch_all();
    var_dump($result);
} else {
    echo "No Result";
}
}
$me['power'] = 0;
$me['money'] = 0;
// Party情報取得を試みる
$party = array();
$partyResult = $Party->findBy(array('president_id' => $facebook->getUser()));
// Partyが0以上 = 誰かしらデッキに入ってる場合
if ($partyResult->num_rows > 0) {
    while ($p = $partyResult->fetch_assoc()) {
        $follower = $Follower->findBy(array('facebook_id' => $p['follower_id']));
        $f = $follower->fetch_assoc();
        if (!is_null($f)) {
            array_push($party, $f);
            $me['power'] += $f['power'];
            $me['money'] += $f['money'];
        }
    }
}
// Partyが空=未選択の場合, /follower/index.phpにリダイレクト
if (count($party) == 0) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /follower/index.php");
}
// Princess情報取得を試みる
$princess = array();
if (isset($me['princess_id'])) {
    $result = $Princess->findBy(array('facebook_id' => $me['princess_id']));
    if ($result->num_rows != 0) {
        $princess = $result->fetch_assoc();
    }
}