来自 MySQL 的值需要刷新 [英] value from MySQL needs to be refreshed

查看:60
本文介绍了来自 MySQL 的值需要刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TEST</title>
<script src="gauge.min.js"></script>
</head>

<?php 
        //maak verbinding met MySQL server:
        $link = mysqli_connect("localhost","root","","opc") 
        or die("Kan niet verbinden met de server " . mysqli_error($link));

        //Haal waarde uit de database:
        $query = "SELECT * FROM test" 
        or die("Er is een fout opgetreden" . mysqli_error($link));

        //Sla de waarde op.
        $result = $link->query($query);

        //toon informatie:

        while($row = mysqli_fetch_array($result)) 
        {
            $waarde2 = $row["waarde2"];
        }
?>

<body>    
    <canvas id="gauge1" width="400" height="400"        
        data-type="canv-gauge"
        data-title="OPC TEST"
        data-min-value="0"
        data-max-value="100"
        data-major-ticks="0 10 20 30 40 50 60 70 80 90 100"
        data-minor-ticks="10"
        data-stroke-ticks="true"
        data-units="RPM"
        data-value-format="3.0"
        data-glow="true"
        data-animation-delay="500"
        data-animation-duration="200"
        data-animation-fn="linear"
        data-colors-needle="#f00 #00f"
        data-onready="setInterval( function() { Gauge.Collection.get('gauge1').setValue( <?= $waarde2 ?>);}, 1000);"
    ></canvas>    
</body>    
</html>

它工作得很好,并显示了一个带有来自 mysql 数据库的值的仪表(它每秒用另一个值更新自己).不幸的是,仪表一直显示相同的数字.有谁知道如何解决这个问题?

It works perfectly and shows a gauge with the value from the mysql database (which updates itself every second with another value). Unfortunately the gauge keeps displaying the same number. Does anyone know how to fix this?

推荐答案

使用 AJAX 将仪表和数据拉入 DIV,然后每隔 ** 毫秒或秒或您需要的任何时间更新 AJAX.然后它就会以您确定的频率发生.

Load the gauge and data pull into a DIV using AJAX and then update AJAX every **ms or seconds or whatever you need. Then it will just happen at the frequency you determine.

这是一种快速简便的方法:Div 更新

This is a quick and easy way to do it: Div Update

这篇关于来自 MySQL 的值需要刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆