gpt4 book ai didi

php 数据库查询 (phpMyAdmin) 只将一个值(第一个)带回 amcharts

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:08 26 4
gpt4 key购买 nike

下面的 php 数据库查询(来自 phpMyAdmin)只将一个值(第一个或最旧的)带回 amcharts:

<?php
class custom_class2
{
var $charts; // reference to the calling object.

function customfunction2($content,$conf)
{
global $TSFE;
$TSFE->set_no_cache();

// do whatever you want here

// db connection
mysql_connect("hostname", "username", "password");
mysql_select_db("database name");

//db abfrage
$query = "
SELECT
YEAR(datetime) AS dy,
MONTH(datetime) -1 AS dm,
DAY(datetime) AS dd,
HOUR(datetime) AS th,
MINUTE(datetime) AS tm,
temp,
hum,
pressure
FROM stock1
ORDER BY datetime
";

// NEW: Variable definition
$zeilenzaehler = 1;

// output of the rows
$result = mysql_query($query) OR die("Error: $query <br>" . mysql_error());
while ($row = mysql_fetch_array($result))
{
// return
if ($zeilenzaehler != 1)
{
$content.= ",";
}

$content.= "{date: new Date(" . $row['dy'] . "," . $row['dm'] . "," . $row['dd'] . "," . $row['th'] . "," . $row ['tm'] . "),t:" . $row['temp'] . ",h:" . $row['hum'] . ",p:" . $row['pressure'] . "}";

return $content;

// Variable now on 2
$zeilenzaehler = 2;
}
}
}
?>

其他一切看起来都正常。非常感谢您的帮助

最佳答案

您在 while 循环中返回第一个找到的结果。这就是为什么你只有一个结果。此外,由于 mysql_* 函数已弃用,请考虑切换到 mysqli_*PDO .我正在根据您的请求添加代码:

<?php
class custom_class2
{
var $charts; // reference to the calling object.

function customfunction2($content,$conf)
{
global $TSFE;
$TSFE->set_no_cache();

// do whatever you want here

// db connection
$mysqli = new mysqli("hostname", "username", "password", "database name");
if ($mysqli->connect_error) {
// your error handling here
}

//db abfrage
$query = "
SELECT
YEAR(datetime) AS dy,
MONTH(datetime) -1 AS dm,
DAY(datetime) AS dd,
HOUR(datetime) AS th,
MINUTE(datetime) AS tm,
temp,
hum,
pressure
FROM stock1
ORDER BY datetime
";

// NEW: Variable definition
$zeilenzaehler = 1;

// output of the rows
$result = $mysqli->query($query);
if (FALSE === $result) {
// you can put different error handling here
echo 'Error: ' . $query . ' ' . $mysql->error);
die();
}
$total = array();
while (NULL !== ($row = $result->fetch_array()))
{
// return
if ($zeilenzaehler != 1)
{
$content.= ",";
}

$content.= "{date: new Date(" . $row['dy'] . "," . $row['dm'] . "," . $row['dd'] . "," . $row['th'] . "," . $row ['tm'] . "),t:" . $row['temp'] . ",h:" . $row['hum'] . ",p:" . $row['pressure'] . "}";

// return $content;
// if you not return the first result you can gather results in array, so array will contain every row in result, $total[0], $total[1]...:
// $total[] = $content; or:
$total[] = "{date: new Date(" . $row['dy'] . "," . $row['dm'] . "," . $row['dd'] . "," . $row['th'] . "," . $row ['tm'] . "),t:" . $row['temp'] . ",h:" . $row['hum'] . ",p:" . $row['pressure'] . "}";

// Variable now on 2
$zeilenzaehler = 2;
}

$result->free();
return $total; // return all rows
}
}
?>

关于php 数据库查询 (phpMyAdmin) 只将一个值(第一个)带回 amcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28394988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com