what i want to do is just display the "bpm" value... the var_dump is showing value but i still cannot display the "bpm" value to screen.
PHP file
<?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);
?>
result :
success connected!!
{"id":"1","bpm":"121 BPM"} //json string
//result should appear here
string(26) "{"id":"1","bpm":"121 BPM"}" //var_dump output
endd
any help is appreciated
**my final working code
<?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);
?>
plus i changed the collation of database from latin to UTF8. thx for the helps!
$rows = $r;to$rows[] = $r;you don't add new element to array but you override array with 1 row during loop