[eluser]CJL01[/eluser]
I'm trying to take one db query result set and use it to both display as a table, and to draw graphs from. I've created my own custom datatable library to format up query results into a table as I need them. I've also created a graph library which takes a query result and formats it into a Google chart URL for display. The first argument in my new_line_chart() function is the column of the $query result set that should be graphed.
Code:
$query = $this->new_model->daily_summary();
$table = $this->datatable->generate($query);
$data['output'] = '<h3>Daily Summary</h3>'.$table;
$graph = $this->graph->new_line_chart(1, 'N', $query);
$data['output'] .= '<br />'.$graph;
$graph = $this->graph->new_line_chart(4, 'N', $query);
$data['output'] .= '<br />'.$graph;
$query->free_result();
I've tested these libraries and functions to ensure they all work, but the problem is that I can't seem to re-use the $query result set from my first query to feed the graph - it seems to have gone out of scope by the time I use it for the graphs. If I re-query each time then it works perfectly;
Code:
$query = $this->new_model->daily_summary();
$table = $this->datatable->generate($query);
$data['output'] = '<h3>Daily Summary</h3>'.$table;
$query = $this->new_model->daily_summary();
$graph = $this->graph->new_line_chart(1, 'N', $query);
$data['output'] .= '<br />'.$graph;
$query = $this->new_model->daily_summary();
$graph = $this->graph->new_line_chart(4, 'N', $query);
$data['output'] .= '<br />'.$graph;
$query->free_result();
It seems really inefficient to re-run exactly the same query three times here, so I want to re-use the same $query object for all three. My datatable and graph functions use field_data(), so I can't use query caching unfortunately.
Anybody have any other ideas?