功能选择相同和相似,计算它们,返回友好名称和计数

时间:2016-02-22 01:03:13

标签: php mysql function mysqli similarity

嘿伙计们这个问题是我的问题here的后续问题。我创建了一个函数来计算我们每年举行的比赛的每列投票数。问题在于,对于文本字段,人们不总是正确地拼写事物,或者使用相同的标点符号,反斜杠最终也会比他们应该更频繁地被包含在数据库中(这让我想知道有时他们是&#39 ;重新获得双重逃脱或其他东西,但已经有太多条目了)

无论如何,我的功能看起来像这样。我想知道是否有办法清理它。例如,如果一个角色关闭,则可以非常安全地假设他们是同一个地方或某个地方。

function get_results_for($column) {
    global $dbc;
    $rowcount = "";
    //This portion fetches unique entries that aren't empty
                $query = "SELECT DISTINCT $column ";
                $query .= "FROM newbob ";
                $query .= "WHERE $column != '' ";
                $query .= "ORDER BY $column ASC";


                $result = mysqli_query($dbc, $query);
                if (!$result){
    die ("Database query failed.");
}

//and I want this portion to count how many there are that are the same, and
//just add it next to it.
while($entries = mysqli_fetch_assoc($result)) {
 foreach ($entries as $entries) {
         echo removeslashes($entries);
                $entries2 = mysqli_real_escape_string($dbc,$entries); }
                $query2 = "SELECT $column ";
                $query2 .= "FROM newbob ";
                $query2 .= "WHERE $column LIKE '%$entries2%'";
                $result2 = mysqli_query($dbc, $query2);
                                if (!$result2){
    die ("<br>Database query failed.");
}
                $rowcount = mysqli_num_rows($result2);

               echo " (" . $rowcount . ")<br>";
 }
    }

这是我回来的截图,如果这有助于让它更清晰。

enter image description here

0 个答案:

没有答案