Exemple #1
0
 public function calcNearUser()
 {
     $this->load->model('item_model', 'items');
     $newUserId = $this->items->newUserId();
     $point = array(5, 3);
     $j = 0;
     for ($i = 1; $i < 11; $i++) {
         if (isset($_POST[$i])) {
             $this->items->newLikeCheck($newUserId, $_POST[$i], $point[$j]);
             $j++;
         }
     }
     $max = 0.0;
     for ($i = 1; $i < $newUserId; $i++) {
         if (isUser($i)) {
             $num = distanceUsers(evalUsers($i, $newUserId));
             if ($num > $max) {
                 $max = $num;
                 $nearUserId = $i;
             }
         }
     }
     $data['newUserId'] = $newUserId;
     $data['recommendItem'] = $this->items->getRecommendItem($nearUserId, $newUserId);
     $this->load->view('items/recommend', $data);
 }
<?php

require_once 'DBaccess.php';
require_once 'functions.php';
session_start();
$recommendee_id = $_SESSION['user_id'];
unset($_SESSION);
$max = 0.0;
for ($i = 1; $i < $recommendee_id; $i++) {
    if (isUser($i)) {
        $num = distanceUsers(evalUsers($i, $recommendee_id));
        if ($num > $max) {
            $max = $num;
            $nearUserId = $i;
        }
    }
}
$sql = sprintf('SELECT item_id FROM likes WHERE user_id=%d', r($recommendee_id));
$recordRecommendeeLikes = mysql_query($sql) or die(mysql_error());
$recommendeeLikesArray = array();
$i = 0;
while ($recommendeeLikes = f($recordRecommendeeLikes)) {
    $recommendeeLikesArray[$i] = $recommendeeLikes['item_id'];
    $i++;
}
$sql = sprintf('SELECT i.* FROM likes l, items i WHERE l.user_id=%d AND l.item_id=i.id AND i.id != %d AND i.id != %d', r($nearUserId), r($recommendeeLikesArray[0]), r($recommendeeLikesArray[1]));
$recordRecommendItem = mysql_query($sql) or die(mysql_error());
$RecommendItem = f($recordRecommendItem);
?>
<!DOCTYPE html>
<html lang="ja">