【问题标题】:php mysql associative array for graph report用于图形报告的 php mysql 关联数组
【发布时间】:2012-10-09 11:17:28
【问题描述】:

我需要像下面这样的输出。我想为我的报告生成一个图表,所以我需要 mysql_fetch_assoc 中的结果。我对这个概念很陌生。基本上是在做 mysql_fetch_array ,但现在我需要关联数组函数。

$date = array("date" => reading);

$data = array("28-Sep-2012" => .0032, "27-Sep-2012" => .0028, "29-Sep-2012" => .0021,
"24-Sep-2012" => .0033);

【问题讨论】:

  • 在我的查询下方:$results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'"); while($row = mysql_fetch_array($results)) { // 我不知道这里会是什么? }
  • 您可以重新生成一个新数组来实现这一点。

标签: php mysql graph


【解决方案1】:

这样试试,

$results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'");
$data=array();
while ($row = mysql_fetch_array($results))
{ 
    $data[$row['date']]=$row['vaccum_value'];
}

print_r($data);

【讨论】:

  • @SureshbalajiGunasekaran:这是简单的 PHP 数组功能。创建一个以日期为键、vaccum_value 为数组值的数组。
  • 但我需要像这个数组这样的输出("28-Sep-2012" => .0032, "27-Sep-2012" => .0028, "29-Sep-2012" => .0021, "2012 年 9 月 24 日" => .0033);而不是 [] 方括号我需要“”老板......在我用你的代码运行脚本后,我得到了这样的输出 Array ([28-Sep-2012] => 31.6 [04-Oct-2012] => 0.99 [2012 年 10 月 3 日] => -3 );
  • 两者相同..数组的键仅为字符串。
猜你喜欢
  • 2016-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多