<?php
Class Popular {
protected $locationType;
protected $locationCode;
protected $numberToGet;
function __construct($locationType, $numberToGet, $locationCode = 1) {
$this->locationType = $locationType;
$this->locationCode = $locationCode;
$this->numberToGet = $numberToGet;
$this->getPopularList();
$this->outputHTML();
}
protected function getPopularList() {
if ($this->locationType == 'City') {
$this->locationType = 'Category';
$this->getPopResource = mysql_query("SELECT * FROM State INNER JOIN Cities ON Cities.StateID=State.id WHERE countryID='$this->locationCode' ORDER BY Cities.popularity DESC LIMIT $this->numberToGet");
} else if ($this->locationType == 'State') {
$this->getPopResource = mysql_query("SELECT * FROM State WHERE countryID='$this->locationCode' ORDER BY popularity DESC LIMIT $this->numberToGet");
} else if ($this->locationType == 'Country') {
$this->getPopResource = mysql_query("SELECT * FROM Countries ORDER BY popularity DESC LIMIT $this->numberToGet");
}
}
protected function outputHTML() {
while ($this->row = mysql_fetch_assoc($this->getPopResource)) {
$this->name = $this->row['name'];
$this->url = LOCATION_CAT . "?locationType=$this->locationType&id=" . $this->row['id'];
$this->htmlToOutput = "<ul>";
$this->htmlToOutput .= "<li><a href='$this->url' title='$this->name'>$this->name</a></li>";
$this->htmlToOutput .= "</ul>";
echo $this->htmlToOutput;
}
}
}
?>