그래서 저는 일하고있는 건물 (관리자 요청)의 웹 사이트에 대한 통계 섹션을 만들고 있습니다. 나는 '24 시간'그래프에 대한 작동 코드를 가지고있다. 그래프 코드 내가 완벽하게 작품을 가지고 있지만 난 이사이트 사용을 위해 SQL과 php를 사용하여 주간 및 월간 그래프 만들기
function get_hourly_graph() {
// First lets create a daily graph for experiment then we can build on that
date_default_timezone_set('Australia/Sydney');
$current_hour = date('H');
// SQL Query to get data we want
$sql = mysql_query("SELECT hour(time_hit) AS hour , count(hour(time_hit)) AS hits FROM hits WHERE time_hit > now() - INTERVAL 1 DAY GROUP BY hour(time_hit);")
or die(mysql_error());
// Remove an hour off current time for array and the loop that will put the data into the array
$array_hour = $current_hour - 1;
// Add a 0 if the timer is under 10. just so this is compatable with the SQL data
if ($array_hour < 10) {
$array_hour = 0 . $array_hour;
}
// initialise the array so we can set up the indexes and data in the next couple of loops
$hit_data = array();
// Work back the clock 24 hours and create the array indexes
for ($i = 0; $i < 24; $i++) {
$new_hour = $current_hour;
if ($new_hour < 1) {
$new_hour = 24;
$hit_data[$new_hour] = "0";
}
else {
$hit_data[$new_hour] = "0";
}
$current_hour = $new_hour - 1;
}
// Loop through the rest of the array and replace null with 0s
while ($results = mysql_fetch_array($sql, MYSQL_ASSOC)) {
foreach ($hit_data as $hour => $hits) {
if ($results['hour'] == $hour) {
$hit_data[$hour] = $results['hits'];
}
}
}
$hit_data = array_reverse($hit_data, true);
// Generate the graph for the 24 hour data
generate_graph ($hit_data, '24 Hour Report', 'hourly_graph.png', 'Time (Hours)', 'Hits');
}
아래
시간별 코드는 '히트'테이블은 기본적으로 보다는 시간
일을 기준으로 데이터를 끌어 MySQL을위한 올바른 코드를 얻는 데 문제 야 'YYYY-MM-DD hh : mm : ss'= "2011-08-04 12:40:34"인 3 개의 필드 'hit_id' 'ip_address' '타임 스탬프'SQL 코드를 어떻게 변경합니까? 몇 시간이 아닌 며칠 동안 일할 수 있습니까?
을 설명해주십시오 –