2012-02-23 103 views
0

我試圖創建一些基於每週的no.of.success和no.of.failure status.i創建了谷歌折線圖選項的圖表,但它試圖從數據庫中獲取值時不起作用。使用谷歌圖表使用PHP和MySQL創建圖表?

我的表名是:細節

代碼如下:

$sql_no=mysql_query("SELECT COUNT(*) AS nof FROM details WHERE result=1"); 
    $call=mysql_fetch_assoc($sql_no); 
    google.load("visualization", "1", {packages:["corechart"]}); 
    google.setOnLoadCallback(drawChart); 
    function drawChart() { 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Month'); 
    data.addColumn('number', 'Success'); 
    data.addColumn('number', 'Failure'); 
    <?php $results = array(); 
    while ($row = mysql_fetch_assoc($sql_no)){ 
    $num=$results[$row['nof']]; 
    } 
    echo 'data.addRows('.count($results).');'; 
    $i = 0; 
    foreach ($results as $value => $num){ 
    echo' 
    data.setValue('.$i.', 0, "'.$value.'"); 
    data.setValue('.$i.', 1, '.$num.'); 
    '; 
    $i++; 
    } 
?> var options = { 
     width: 800, height: 340, 
     title: 'Call details' 
    }; 
    var chart = 
    new google.visualization.LineChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
    } 

回答

0

混合PHP和JavaScript是一個爛攤子.. 看什麼格式的谷歌API預計,在數據陣列,創建它在純粹的PHP,然後json_encode()