2010-03-16 65 views
2

我想只顯示帶有的文字 4個字符,實際上我可以限制匹配並只顯示最小的單詞。 100次點擊 - 但我怎樣才能設置分鐘。字符長度?謝謝!最少4個字符或者什麼都不顯示 - PHP

function sm_list_recent_searches($before = '', $after = '', $count = 20) { 
// List the most recent successful searches. 
    global $wpdb, $table_prefix; 
    $count = intval($count); 
    $results = $wpdb->get_results(
     "SELECT `terms`, `datetime` 
     FROM `{$table_prefix}searchmeter_recent` 
     WHERE 100 < `hits` 
     ORDER BY `datetime` DESC 
     LIMIT $count"); 
    if (count($results)) { 

     foreach ($results as $result) { 
      echo '<a href="'. get_settings('home') . '/search/' . urlencode($result->terms) . '">'. htmlspecialchars($result->terms) .'</a>'.", "; 
     } 

    } 
} 

回答

1

如果使用的是MySQL:

WHERE 100 < `hits` AND CHAR_LENGTH('yourField') > 4 
+0

plussing這一點,因爲它是第一個和我一個字符串與char_length混合在一起 – Gordon 2010-03-16 14:08:01

2

MySql manual

CHAR_LENGTH(STR) 返回字符串str的長度,以字符測量。多字節字符計爲單個字符。這意味着,對於含有五兩字節字符,length()返回10,而CHAR_LENGTH()返回5

所以你添加

where(char_length(terms) > 4)) 
相關問題