//Connect To Database
$hostname="localhost";
$username="jt6mm0c_db19116";
$password="pn@IUO?hh8kbHj5A";
$dbname="jt6mm0c_db19116_emocapsule";
mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);
//getting emotion
$emotion = $_POST['emotion'];
$loc = $_REQUEST['loc'];
date_default_timezone_set('EST5EDT');
$now = time();
$date = strftime('%H_%M_%S_%b%d%y',$now);
// echo $date;
if(isset($_COOKIE['city']) && isset($_COOKIE['country'])){
//print "you are in {$_COOKIE['city']}.";
$localCity = $_COOKIE['city'];
$localCountry = $_COOKIE['country'];
}
//displaying the users location
//echo "$localCity $localCountry
";
if (!isset($_REQUEST['display'])){
$display = 5;
//echo $display;
}else{
$display = $_REQUEST['display'];
//echo $display;
}
$location = $_REQUEST['location'];
////////////////////////////////////////
$now = time();
date_default_timezone_set('EST5EDT');
$date = strftime('%H_%M_%S_%b%d%y',$now);
// echo $date;
if(isset($_COOKIE['city']) && isset($_COOKIE['country'])){
//print "you are in {$_COOKIE['city']}.";
$localCity = $_COOKIE['city'];
$localCountry = $_COOKIE['country'];
}
if (!isset($_REQUEST['display'])){
$display = 5;
}else{
$display = $_REQUEST['display'];
}
$location = $_REQUEST['location'];
/*echo $display;*/
//$allCities = @mysql_query("SELECT DISTINCT city FROM webEmotion GROUP BY city ORDER BY `city` DESC");
//$numCities=mysql_numrows($allCities);
//echo $numCities;
// for global display or when page first loads...
$totalWeather = @mysql_query("SELECT weatherC, count( weatherC ) AS num_times FROM webEmotion GROUP BY weatherC ORDER BY `num_times` DESC");
$totalWeatherNum=mysql_numrows($totalWeather);
$emotionWeatherOrdered = @mysql_query("SELECT weatherC FROM webEmotion");
$numWeather=mysql_numrows($emotionWeatherOrdered);
//echo "$totalWeatherNum
";
//if the location is the users local city
$i=0;
while($i<$totalWeatherNum){
$weather_[$i] = mysql_result($totalWeather, $i, 'weatherC');
$num_loc_[$i] = mysql_result($totalWeather, $i, 'num_times');
//echo "num of cities shown $num_loc_[$i]";
$percentage[$i] = ceil((($num_loc_[$i]/$numWeather)*100));
//for the pixels
// $num_loc_[$i] = ceil(500-(($num_loc_[$i]/$numWeather)*500));
$num_loc_[$i] = ceil((($num_loc_[$i]/$numWeather)*500));
//echo "percentage$percentage[$i]";
//echo "city pixel $num_loc_[$i]";
/*echo $num_test_[$i];?>
*/
$i++;
}
// *********** THE $num_loc_ VARIABLE DOES NOT TO BE JOINED INTO AN ARRAY!
//$num_loc_ = join(",",$num_loc_);
//$cityArray = join(",",$city_);
$string = '';
foreach($weather_ as $key => $value){
$string .="$value|";
}
$string = str_replace(' ', '', $string);
?>
// *********** THE $num_loc_ VARIABLE DOES NOT TO BE JOINED INTO AN ARRAY!
$test_data = $num_loc_;
// Here's where we call the chart, and return the encoded chart data
//echo "
";
//dynamic graph witdh
$graphWidth = ((60*$totalWeatherNum)+100);
/*
EXAMPLE PHP ENCODING
echo "
";
*/
echo "
";
// And here's the function
function chart_data($values) {
// Port of JavaScript from http://code.google.com/apis/chart/
// http://james.cridland.net/code
// First, find the maximum value from the values given
//$maxValue = max($values);
$maxValue = 500;
// A list of encoding characters to help later, as per Google's example
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
// Return the chart data - and let the Y axis to show the maximum value
return $chartData;
}
?>