I use this code:
$result = mysql_query("SELECT * FROM data WHERE user_id='$user_id'");
$output_array = array();
while ($row = mysql_fetch_array($result)) {
if(!isset($output_array[$row['plant_id']]) || !is_array($output_array[$row['plant_id']])){
$output_array[$row['plant_id']] = array();
}
$output_array[$row['plant_id']][$row['date']] = $row['value'];
}
to get this array:
Array
(
[100] => Array
(
[2011, 03, 03] => 111111
[2010, 12, 03] => 123123
)
[101] => Array
(
[2011, 01, 01] => 123555
[2011, 01, 27] => 999
[2011, 04, 20] => 123555
)
)
Using Smarty I looped this values as follows (inside JS):
{foreach from=$output_array key=plant_id item=date_value}
name: '{$plant_id}',
data: [{foreach key=date item=value from=$date_value}
[Date.UTC({$date}), {$value}],
{/foreach}]
{/foreach}
But now I would like to get this working back on raw PHP (without Smarty) - does anyone know how to translate these Smarty loops back to PHP?
Any help / pointers are much appreciated!