我想要做的只是显示“bpm”值...... var_dump 正在显示值,但我仍然无法在屏幕上显示“bpm”值。
PHP 文件
<?php
include ('open.php'); //open database connection
$sth = mysql_query("SELECT * FROM heartbeatTB");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows = $r;
}
$decoded_json= json_encode($rows);
print_r($decoded_json);
foreach($decoded_json as $de){
echo $de['id']['bpm']; } //not displaying output
echo "<br><br>";
var_dump($decoded_json);
echo "<br><br>endd";
mysql_close($con);
?>
结果 :
success connected!!
{"id":"1","bpm":"121 BPM"} //json string
//result should appear here
string(26) "{"id":"1","bpm":"121 BPM"}" //var_dump output
endd
任何帮助表示赞赏
* *我的最终工作代码
<?php
include ('open.php');
$sth = mysql_query("SELECT bpm FROM heartbeatTB");
//$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows = $r;
}
$string_json= json_encode($rows);
print_r($string_json); ////////////////
echo "<br><br>";
$result=json_decode($string_json);
var_dump($result->bpm); //////////////
echo "<br><br> the answer :".$result->bpm ;
echo "<br><br>";
var_dump($string_json); ////////////
echo "<br><br>end";
mysql_close($con);
?>
另外,我将数据库的排序规则从拉丁语更改为 UTF8。谢谢你的帮助!