Skip to content

JOIN support #11

Description

@bggardner

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());
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions