0

文があります。単語に分割して、ストップワードテーブルのデータで確認します。同じデータの数(合計)を数えたいです。ただし、totalでは同じデータの合計は得られません。必要なデータを合計する方法は?ありがとう

$word ='temporal. the text mining in a evolutionary a theme patterns  theme threads  clustering'; 
$symbol    = array(".", ",", "\\", "-", "\"", "(", ")", "<", ">", "?", ";", ":", "+", "%", "\r", "\t", "\0", "\x0B");
$cleanMeta = str_replace($symbol, " ", $word);
$key     = strtolower($cleanMeta);
$key = explode(" ", trim($key));

foreach($key as $word_key){
    $query = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword  WHERE stoplist_word = '$word_key'");
    while ($row = mysql_fetch_array($query)) {
        $row1 = $row['total'];
        echo $row1;
    }
}
4

1 に答える 1

1

入力文字列を既にクリーンアップしていることを考えると、すべての単語に対して新しいクエリを使用するforeachは必要ありません。あなたができること:

$word ='temporal. the text mining in a evolutionary a theme patterns  theme threads  clustering'; 
$symbol    = array(".", ",", "\\", "-", "\"", "(", ")", "<", ">", "?", ";", ":", "+", "%", "\r", "\t", "\0", "\x0B");
$cleanMeta = str_replace($symbol, " ", $word);
$key       = trim(strtolower($cleanMeta));
$key       = str_replace("'","''",$key);
$keys      = "'".str_replace(" ","', '", $key)."'";

$query  = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword  WHERE   stoplist_word IN ($keys)");
$row    = mysql_fetch_array($query);
$total = $row['total'];

echo $total;

本当にforeachを使用したい場合:

$total = 0;
foreach($key as $word_key){
    $query = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword  WHERE stoplist_word = '$word_key'");
    while ($row = mysql_fetch_array($query)) {
        $total += $row['total'];
    }
}
echo $total;
于 2012-12-05T09:01:45.160 に答える