index.php:
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<title>Страница статистики</title>
</head>
<body>
<?php
$link = mysqli_connect("localhost","server","qwerty","SentimentAnalysis");
mysqli_set_charset($link, "utf8");
?>
<?php
$dir='/var/www/texts/';
$texts=scandir($dir);
$text=rand(2,count($texts));
$path=$dir . $texts[$text];
echo file_get_contents($path);
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
$link = mysqli_connect("localhost","server","qwerty","SentimentAnalysis");
$sentiment=htmlspecialchars($_POST["sentiment"]);
$emotion=htmlspecialchars($_POST["emotion"]);
$sql='update texts set '.$sentiment.'='.$sentiment."+1 where path='".htmlspecialchars($_POST["path"])."';";
mysqli_query($link,$sql);
$sql='update texts set '.$emotion.'='.$emotion."+1 where path='".htmlspecialchars($_POST["path"])."';";
mysqli_query($link,$sql);
$sql='select path from texts where positive+negative>=16;';
$arr=mysqli_fetch_array(mysqli_query($link,$sql));
if (!empty($arr)){
foreach ($arr as $value){
$txt=file_get_contents($value);
$sent=max(mysqli_fetch_array(mysqli_query($link,'select positive,negative from texts where path='."'".$value."';")));
$emot=max(mysqli_fetch_array(mysqli_query($link,'select good,well,sad,angry from texts where path='."'".$value."';")));
$sql='update cnt set'.$emot.'='.$emot.'+1,'.$sent.'='.$sent.'+1;';
mysqli_query($link,$sql);
mysqli_query($link,'delete from texts where path='."'".$value."';");
$lits='абвгдежзиклмнопрстуфхцчшщъыьэюя';
for ($i=0; $i<strlen($lits); $i++){
$char = substr($lits,$i,1);
$avg = substr_count($txt, $char)/strlen($txt);
$sent_pre_avg=mysqli_query($link,'select '.$sent." from letters where letter='".$char."';");
$dim_sent=mysqli_query($link,'select '.$sent." from cnt;");
$emot_pre_avg=mysqli_query($link,'select '.$emot." from letters where letter='".$char."';");
$dim_emot=mysqli_query($link,'select '.$emot." from cnt;");
$new_avg_sent=($sent_pre_avg*$dim_sent+$avg)/($dim_sent+1);
$new_avg_emot=($emot_pre_avg*$dim_emot+$avg)/($dim_emot+1);
mysqli_query($link,"update letters set ".$sent."=".$new_avg_sent.",".$emot."=".$new_avg_emot.";");
}
}
}
}
?>
<form action="index.php" method="post">
<p>Как вы оцениваете общее настроение этого текста? </p>
<input type="radio" name="sentiment" value="positive">Положительное</input>
<input type="radio" name="sentiment" value="negative">Отрицательное</input>
<p>Какую эмоцию передает этот текст? </p>
<input type="radio" name="emotion" value="good">Счастье</input>
<input type="radio" name="emotion" value="well">Удовлетворенность</input>
<input type="radio" name="emotion" value="sad">Грусть</input>
<input type="radio" name="emotion" value="angry">Злость</input>
<p><input type="submit" value="Отправить"/></p>
<input type="hidden" name="path" value="<?php echo $path?>"/>
</form>
</body>
</html>
Ошибка возникает такая:
Warning: max(): When only one parameter is given, it must be an array in /var/www/html/index.php on line 32
32 строка выглядит так:
$sent=max(mysqli_fetch_array(mysqli_query($link,'select positive,negative from texts where path='."'".$value."';")));
Но ведь аргумент функции max - это массив, ведь mysqli_fetch_array возвращает массив.
К слову, вот как выглядит таблица texts:
+--------------------------+----------+----------+------+------+------+-------+
| path | positive | negative | good | well | sad | angry |
+--------------------------+----------+----------+------+------+------+-------+
| /var/www/texts/text2.txt | 0 | 0 | 0 | 0 | 0 | 0 |
| /var/www/texts/text3.txt | 0 | 0 | 0 | 0 | 0 | 0 |
| /var/www/texts/text4.txt | 0 | 0 | 0 | 0 | 0 | 0 |
| /var/www/texts/text1.txt | 13 | 5 | 0 | 0 | 12 | 0 |
+--------------------------+----------+----------+------+------+------+-------+
Совсем запутался(