我有以下代码:
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'string'),
array('label' => 'Charging Current', 'type' => 'number'),
array('label' => 'Battery Voltage', 'type' => 'number'),
array('label' => 'Charging Power', 'type' => 'number'),
array('label' => 'Rotation', 'type' => 'number'),
);
并想知道如何更改它,以便能够更改列数。显示列,取决于变量(类似这样):
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'string'),
if ($current == "true") {**
array('label' => 'Charging Current', 'type' => 'number'),
}
if ($voltage == "true") {
array('label' => 'Battery Voltage', 'type' => 'number'),
}
if ($power == "true") {
array('label' => 'Charging Power', 'type' => 'number'),
}
if ($rotation == "true") {
array('label' => 'Rotation', 'type' => 'number'),
}
);
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$temp = array();
// the following line will be used to slice the chart
$temp[] = array('v' => (string) $r['TimeStamp']);
// Values of each slice
if ($current == "true") {
$temp[] = array('v' => (int) $r['ChargingCurrent']);
$rows[] = array('c' => $temp);
}
if ($voltage == "true") {
$temp[] = array('v' => (int) $r['BatteryVoltage']);
$rows[] = array('c' => $temp);
}
if ($power == "true") {
$temp[] = array('v' => (int) $r['ChargingPower']);
$rows[] = array('c' => $temp);
}
if ($rotation == "true") {
$temp[] = array('v' => (int) $r['Rotation']);
$rows[] = array('c' => $temp);
}
}
我希望很清楚我要做什么。请帮我。