WPDB – How to search a column in a table

What you are asking for should be straight SQL.

Try adapting the following:

function check_for_ip($ip) {
    global $wpdb;
    $sql = <<<SQL
        SELECT true
        FROM `wpgrating`
        WHERE `ip` = %s
SQL;
    return (bool) $wpdb->get_var($wpdb->prepare($sql, $ip));
}

In essence, we do a simple SELECT with the IP in question as in the WHERE clause. (Note that it’s important that we don’t use the otherwise standard SELECT 1 as WordPress’ database abstractor will always return false for that.) Because we are not selecting an entire row, we avoid a lot of overhead..