开发者

Minimum 4 Characters or Show Nothing - PHP

I want to show up only words with minimum 4 Characters, actually I can limit the hits and show only words with min. 100 hits - but how can I set a min. character length? thank you!

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_set开发者_StackOverflowtings('home') . '/search/' . urlencode($result->terms) . '">'. htmlspecialchars($result->terms) .'</a>'.", ";
        }

    }
}


From the MySql manual:

CHAR_LENGTH(str) Returns the length of the string str, measured in characters. A multi-byte character counts as a single character. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.

So you add

where(char_length(terms) > 4))


If you are using mySQL:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜