2017-03-14 98 views
0

html的我有數據庫,我只不過,檢索從它只有一個單元格,下面是一個例子:返回數據從MySQL

+------+ 
|Failed| 
+------+ 
|325 | 
+------+ 

我試圖將此值添加到多在我的HTML文件區域,但是我無法做到這一點,下面是HTML文件:

JSON:

$(document).ready(function() { 

$.getJSON('PHP/Faild.php', function(GetFailedRenew) { 
     // set the html content of the id myThing to the value contained in data 
     $("#myThing").html(data.value); 
    }); 
}); 

HTML體樣本:

<div class="inner"> 
<h3>150</h3> 
<p id="myThing"></p> 
</div> 

Failed.php

<?php 

$DB_NAME = 'test'; 
$DB_HOST = 'localhost'; 
$db_port = '3306'; 
$DB_USER = 'root'; 
$DB_PASS = 'mysql'; 

$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); 

    if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
    } 



    $result = $mysqli->query('SELECT RenewFailed FROM Statistics where id=(select max(id) from Statistics);'); 
    $rows = array(); 
    $table = array(); 
    $table['cols'] = array(
    array('label' => 'RenewFailed', 'type' => 'number') 

); 
    foreach($result as $r) { 

     $temp = array(); 

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

$table['rows'] = $rows; 

// convert data into JSON format 
$SubsStats = json_encode($table); 
echo $SubsStats; 

?> 

,這是failed.php的outpout:

{"cols":[{"label":"RenewFailed","type":"number"}],"rows":[{"c":[{"v":"325"}]}]} 

我在PHP和JSON一個新手,所以請讓我知道是否有任何其他/更好的方式來實現上述..

感謝 阿里

+2

這看起來像一個錯字:'$ .getJSON('PHP/Faild.php')' –

+0

typo也許? $ .getJSON('PHP/Failed.php', – Goran

+0

你得到的錯誤是什麼?你只能說沒有工作。 – sfratini

回答