代码正常,数据库能够接收数据并通过php代码不断更新。
问题是,数据($ hb2,不断更新到表的同一行(id = 1& id = 2))无法通过下面显示的代码显示。
每隔0.5秒调用一次PHP。
php代码:
<?php
$hb2 =$_POST['hb']; //fetch data from an application
// Create connection
$con=mysqli_connect("localhost","lala","1234","heartbeatDB");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
echo " success connected!!<br>";
//working, database showing the data
mysqli_query($con,"UPDATE heartbeatTB SET bpm='{$hb2}'
WHERE ID=1 ");
// works too
mysqli_query($con,"UPDATE heartbeatTB SET bpm='{$hb2}'
WHERE ID=2 ");
$result = mysqli_query($con,"SELECT * FROM heartbeatTB");
while($row = mysqli_fetch_array($result))
{
echo "id is >>>>" .$row['id'] ."<br>";
echo "bpm >>>> " .$row['bpm'] ."<br>show<br>";
echo "<br>";
}
mysqli_close($con);
?>
我已经创建了2行并在行中输入了数据(id = 3和id = 4),并且可以显示代码。
这是php文件的输出:
success connected!!
id is >>>>1
bpm >>>> //data from database, which is keep updating**cannot display**
show
id is >>>>2
bpm >>>> //data from database, which is keep updating**cannot display**
show
id is >>>>3 //row created byself
bpm >>>> j88 bmp
show
id is >>>>4 //row created byself
bpm >>>> 60 BPM
show
再次,一切正常,但显示部分.. 非常感谢任何帮助