你可以把你的原始碼貼上來大家幫你看一下,
有時候不一定是範例的問題。
我看有些文章寫說
可以先轉成json再讀
可是我轉完data是空的
<?php
$data = array();
while($row = mysql_fetch_array( $result )){$data[] = $row;}
$json = json_encode($data);
echo json_encode($data);
echo "<script>var data = $json</script>";
?><br>
<script>
angular
.module('myApp', ['trNgGrid'])
.controller("MainCtrl", ["$scope", function ($scope) {
$scope.myItems = data;
}]);
</script>
<body ng-app="myApp">
<div ng-controller="MainCtrl">
<table tr-ng-grid='' items='myItems'>
</table>
</div>
</body>
之後我自己弄好了
我改用PDO連資料庫
他才抓得到資料轉JSON
我也不知道為什麼
$db_host = "";
$db_user = "";
$db_pass = "";
$db_select = "";
$dbconnect = "mysql:host=".$db_host.";dbname=".$db_select;
$db=new PDO($dbconnect, $db_user, $db_pass);
$row=$db->prepare('select * from account');
$row->execute();//execute the query
$json_data=array();//create the array
foreach($row as $rec)//foreach loop
{
$json_array['dateAndTime']=$rec['dateAndTime'];
$json_array['category']=$rec['category'];
$json_array['content']=$rec['content'];
$json_array['sum']=$rec['sum'];
//here pushing the values in to an array
array_push($json_data,$json_array);
}
//built in PHP function to encode the data in to JSON format
$dataA = json_encode($json_data);
echo "<script>var data = $dataA</script>";