Last active
March 1, 2024 14:08
-
-
Save davidpede/bbf69d7c1a04dae6e32e997b59d4283b to your computer and use it in GitHub Desktop.
Group_concat in XPDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$query = $this->modx->newQuery('ClassName'); | |
$query->where(array( | |
'project_id' => x | |
,'unit_id' => y | |
)); | |
$query->select(array( | |
'ClassName.*', | |
'array_node' => 'GROUP_CONCAT(DISTINCT colname_from_joined_table SEPARATOR " , ")' | |
)); | |
//example 2 | |
$query->select(array( | |
'tag_ids' => 'GROUP_CONCAT(DISTINCT Tags.tag SEPARATOR ",")' | |
)); | |
$query->leftJoin('ClassName2','Alias'); | |
$query->prepare(); | |
if ($query->prepare() && $query->stmt->execute()) { | |
$array = $query->stmt->fetchAll(PDO::FETCH_ASSOC); //view all returned data | |
} | |
$this->modx->log(xPDO::LOG_LEVEL_ERROR,'Label: ' . print_r($array, true)); | |
$output = $this->toJSON($array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment