0

代码正在运行,数据库能够接收数据并通过 php 代码不断更新。

问题是,数据($hb2,不断更新到表的同一行(id=1 & id=2))无法通过下面显示的代码显示。

php 每 0.5 秒调用一次。

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

再次,一切正常,但显示部分..任何帮助都非常感谢

4

0 回答 0