-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
Description
The Google Visualization Query language does not support JOINs, and I am not currently planning to implement JOINs in google-visualization-php. However, JOINs can be accomplished with a little more leg work using one of these work-arounds:
- Server-side in SQL:
- Create a SQL View that performs any necessary JOIN(s) and pass the name of the view to xxxDataSourceHelper instead of a table name.
CREATE VIEW `report` AS SELECT * FROM `scores` JOIN `people` ON `scores`.`person` = `people`.`id`- Server-side in PHP:
- Execute the JOIN in SQL, then apply the Google Query to the entire data set.
public function generateDataTable(Google\Visualization\DataSource\Query $query)
{
$pdo = new PDO("mysql:host=xxx;port=xxx;dbname=xxx", "username", "password");
$stmt = $pdo->query("SELECT * FROM `table1` JOIN `table2` ON `table1`.`col` = `table2`.`col`");
$dataTable = Google\Visualization\DataSource\Util\Pdo\MySqlPdoDataSourceHelper::buildTable($stmt);
return Google\Visualization\DataSource\DataSourceHelper::applyQuery($query, $dataTable, Locale::getDefault());
}
- Client-side in JavaScript:
- Execute a query for each table involved in the JOIN and use google.visualization.data.join() to perform the desired JOIN(s).