<?php
	function getVisitorData ($conn2, $thisPage) {
		$countryList = array(); 
		$total = $total2 = $counter = $counter2 = $ctr = 0;
		$country = $list_data = ''; 
		$sql = 
		" SELECT * FROM users ".
		" WHERE exhibitor_id is null ".
		//" AND id > 14 ".
		" ORDER BY country ";
		if ($hasil = mysql_query($sql, $conn2)) {
			$total_record = mysql_num_rows($hasil);
			while ($data = mysql_fetch_array($hasil)) {
				$ctr++;
				if ($country != $data["country"]) {
					if ($country) {
						$countryList[] = array(
							"negara"  => $country,
							"total"   => $counter,
							"total2"  => $counter2
						);						
						$total 	= $total  + $counter;
						$total2 = $total2 + $counter2;
					}
					$country = $data["country"];	
					$counter = $counter2 = 0;
				}
				if ($ctr == $total_record) {
					$counter++;
					if ($data["is_verify"] == 1) $counter2++;
					
					$countryList[] = array(
						"negara"  => $data["country"],
						"total"   => $counter,
						"total2"  => $counter2
					);						
					$total  = $total  + $counter;
					$total2 = $total2 + $counter2;
				} else {
					$counter++;
					if ($data["is_verify"] == 1) $counter2++;
				}
			}
		}
		//arsort($countryList);
		//var_dump($countryList);

		foreach ($countryList as $key => $row) {
			$s_negara[$key] = $row["negara"];
			$s_total[$key]  = $row["total"];
			$s_total2[$key] = $row["total2"];
		}
		array_multisort($s_total,SORT_DESC, $s_negara,SORT_ASC,  $countryList);
		
		return array($countryList, $total, $total2);	
	}
	?>