2013-10-10 91 views
0

我有一個圖表顯示了一個人預訂的展位總數,但是我想顯示該人在一週中的某一天預訂的展位數量。如何在圖表中顯示每週的每週數據?

下面是我的代碼,顯示了總預訂:

<?php 
    $current_day = date("N"); 
    $days_to_sat = 6 - $current_day; 
    $days_from_sun = $current_day - 0; 
    $monday = date("d-m-y", strtotime("- {$days_from_sun} Days")); 
    $friday = date("d-m-y", strtotime("+ {$days_to_sat} Days")); 
    echo $monday."&nbsp; To &nbsp;".$friday; 



    $c=$_SESSION['user']; 
    $sth =mysql_query("SELECT count(`booth_number`) AS 'booth',`sold_by` FROM `registration1` where week(`Date`) = week(curdate()) and where `sold_by`= '$c' "); 

    $rows = array(); 
    $flag = true; 
    $table = array(); 
    $table['cols'] = array(

    array('label' => 'sold_by', 'type' => 'string'), 
    array('label' => 'booth', 'type' => 'number') 

); 

$rows = array(); 
    while($r = mysql_fetch_assoc($sth)) { 
    $temp = array(); 
    $temp[] = array('v' => (string) $r['sold_by']); 

    $temp[] = array('v' => (int) $r['booth']); 
$rows[] = array('c' => $temp); 
    } 

    $table['rows'] = $rows; 
    $jsonTable = json_encode($table); 

?> 

<!--Load the Ajax API--> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script type="text/javascript"> 

// Load the Visualization API and the piechart package. 
google.load('visualization', '1', {'packages':['corechart']}); 

// Set a callback to run when the Google Visualization API is loaded. 
google.setOnLoadCallback(drawChart); 

function drawChart() { 

    // Create our data table out of JSON data loaded from server. 
    var data = new google.visualization.DataTable(<?=$jsonTable?>); 
var options = { 
    title:" Total Booth Booked ", 
     width: 400, height: 200, 

     minorTicks: 5 
    }; 
    // Instantiate and draw our chart, passing in some options. 
    // Do not forget to check your div ID 
    var chart = new google.visualization.BarChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
} 
</script> 

<!--this is the div that will hold the pie chart--> 
<div id="chart_div"></div> 
+0

任何機構那裏幫助我在這 – mamtasingla

回答

0

獲取所有天爲當前周:

$week = array(); 
$start = new DateTime; 
$start->setISOdate($start->format('o'), $start->format('W')); 
$days = new DatePeriod($start, new DateInterval('P1D'), 6); 
foreach ($days as $day) { 
    $week[$day->format('w')] = array('format' => $day->format('Y-m-d'), 'day' => $day); 
} 

取當前周的所有記錄,按天數進行分組:

$sql = " 
    SELECT COUNT(`booth_number`) AS booth, DATE_FORMAT(`Date`, '%w') AS day_of_week 
    FROM `registration1` 
    WHERE WEEK(`Date`, 3) = '{$start->format('W')}' AND `sold_by` = '{$_SESSION['user']}' 
    GROUP BY day_of_week 
"; 
$result = mysql_query($sql) or die('ERROR: ' . mysql_error()); 

將DB結果寫入$week數組:

while($row = mysql_fetch_assoc($result)) { 
    $week[$row['day_of_week']]['row'] = $row; 
} 

現在你每一天陣列,你想要的結果:

print_r($week);