정말 고마워요! 이제 또 다른 오류가 있습니다. 경고 : 0으로 나누기 이것은 나머지 코드입니다.
while($i<$n_utenti)
{
$query3 = $mysqli->query("SELECT * FROM valutazione WHERE email='$lista_utenti[$i]'");
$indice=0;
while($row = mysqli_fetch_array($query3)) //acquisisco le votazioni dell'utente considerato per il confronto
{
$album_utente_confronto[$indice]=$row['id_album'];
$voti_utente_confronto[$indice]=$row['voto'];
$indice++;
}
//trovo gli album che sono stati valutati da entrambi gli utenti
$indice=0;
$n_album_loggato=count($album_utente_loggato);
$n_album_confronto=count($album_utente_confronto);
$ind=0;
for($indice=0;$indice<$n_album_loggato; $indice++)
{
$index=0;
while($index<$n_album_confronto)
{
if($album_utente_loggato[$indice]==$album_utente_confronto[$index])
{
$album_comuni[$ind]=$album_utente_loggato[$indice];
$ind++;
}
$index++;
}
}
//mi trovo i voti relativi agli album comuni per l'utente loggato
$n_album_comuni = count($album_comuni);
$indice=0;
$i_comuni=0;
for($indice=0;$indice<$n_album_comuni; $indice++)
{
$index=0;
$trovato=false;
while($index<$n_album_loggato && $trovato==false)
{
if($album_comuni[$indice]==$album_utente_loggato[$index])
{
$voti_comuni_logged[$i_comuni] = $voti_utente_loggato[$index];
$trovato = true;
$i_comuni++;
}
else
{
$index++;
}
}
}
//mi trovo i voti relativi agli album comuni per l'utente confrontato
$indice=0;
$i_comuni=0;
for($indice=0;$indice<$n_album_comuni; $indice++)
{
$index=0;
$trovato=false;
while($index<$n_album_confronto && $trovato==false)
{
if($album_comuni[$indice]==$album_utente_confronto[$index])
{
$voti_comuni_confronto[$i_comuni] = $voti_utente_confronto[$index];
$trovato = true;
$i_comuni++;
}
else
{
$index++;
}
}
}
$correlation[$i] = Correlation($voti_comuni_logged, $voti_comuni_confronto);
$i++;//chiusura while
}
//Displaying the calculated Correlation:
print $correlation[0];
}
//The functions that work behind the scene to calculate the
//correlation
function Correlation($arr1, $arr2)
{
$correlation = 0;
$k = SumProductMeanDeviation($arr1, $arr2);
$ssmd1 = SumSquareMeanDeviation($arr1);
$ssmd2 = SumSquareMeanDeviation($arr2);
$product = $ssmd1 * $ssmd2;
$res = sqrt($product);
$correlation = $k / $res;
return $correlation;
}
function SumProductMeanDeviation($arr1, $arr2)
{
$sum = 0;
$num = count($arr1);
for($i=0; $i<$num; $i++)
{
$sum = $sum + ProductMeanDeviation($arr1, $arr2, $i);
}
return $sum;
}
function ProductMeanDeviation($arr1, $arr2, $item)
{
return (MeanDeviation($arr1, $item) * MeanDeviation($arr2, $item));
}
function SumSquareMeanDeviation($arr)
{
$sum = 0;
$num = count($arr);
for($i=0; $i<$num; $i++)
{
$sum = $sum + SquareMeanDeviation($arr, $i);
}
return $sum;
}
function SquareMeanDeviation($arr, $item)
{
return MeanDeviation($arr, $item) * MeanDeviation($arr, $item);
}
function SumMeanDeviation($arr)
{
$sum = 0;
$num = count($arr);
for($i=0; $i<$num; $i++)
{
$sum = $sum + MeanDeviation($arr, $i);
}
return $sum;
}
function MeanDeviation($arr, $item)
{
$average = Average($arr);
return $arr[$item] - $average;
}
function Average($arr)
{
$sum = Sum($arr);
$num = count($arr);
return $sum/$num;
}
function Sum($arr)
{
return array_sum($arr);
}
오류는이 행의 함수 상관에 있습니다. $ correlation = $ k / $ res; 왜 나에게 오류가 발생합니까? 나는 0과 1 사이의 값을 가지고있다
이것을 변경해야합니다.
while($i<=$n_utenti)
이에:
while($i<$n_utenti)
$n_utenti
의 레코드 수보다 1 씩 큽니다 $lista_utenti
.
그렇지 않으면 사용하는 것이 더 깨끗할 것입니다.
foreach($lista_uteni as $email){
기반 루프. (그리고 이런 식으로 하나의 임시 변수를 단계적으로 제거 할 수 있습니다.)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다