Skip to content

Commit

Permalink
Prepare the sql in get top country
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafasoufi committed Dec 28, 2022
1 parent 75e6887 commit 36ebdc6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion includes/class-wp-statistics-country.php
Expand Up @@ -87,8 +87,11 @@ public static function getTop($args = array())
$where = $wpdb->prepare("WHERE `last_counter` BETWEEN %s AND %s", $args['from'], $args['to']);
}

$limit = (isset($args['limit']) and $args['limit'] > 0) ? $wpdb->prepare("LIMIT %d", $args['limit']) : '';
$sql = "SELECT `location`, COUNT(`location`) AS `count` FROM `" . DB::table('visitor') . "` {$where} GROUP BY `location` ORDER BY `count` DESC {$limit}";

// Get Result
$result = $wpdb->get_results("SELECT `location`, COUNT(`location`) AS `count` FROM `" . DB::table('visitor') . "` " . $where . " GROUP BY `location` ORDER BY `count` DESC " . ((isset($args['limit']) and $args['limit'] > 0) ? "LIMIT " . $args['limit'] : ''));
$result = $wpdb->get_results($sql);

foreach ($result as $item) {
$item->location = strtoupper($item->location);
Expand Down

0 comments on commit 36ebdc6

Please sign in to comment.