<?php // Let's Define the Query $strQuery = 'SELECT project.*, ( SELECT COUNT(*) FROM team_member_project_assn WHERE project_id = project.id ) AS __team_member_count FROM project'; // Get the Database object from the Project table $objDatabase = Project::GetDatabase(); ?> <h3>List All the Projects and Its Team Member Count</h3> <?php // Query() the Database and Instantiate on the ResultSet into a Project[] array $objProjectArray = Project::InstantiateDbResult($objDatabase->Query($strQuery)); // Iterate through the Project array foreach ($objProjectArray as $objProject) { _p(QApplication::HtmlEntities($objProject->Name) . ' has ' . $objProject->GetVirtualAttribute('team_member_count') . ' team members.'); _p('<br/>', false); } ?>
public function dtgProjects_Bind() { // Get Total Count b/c of Pagination $this->dtgProjects->TotalItemCount = Project::CountAll(); $objDatabase = Project::GetDatabase(); $objClauses = array(); if ($objClause = $this->dtgProjects->OrderByClause) { $objClauses[] = $objClause; } if ($objClause = $this->dtgProjects->LimitClause) { $objClauses[] = $objClause; } // Create a virtual attribute that lets us know if this Project is related to ACME $objClauses[] = QQ::Expand(QQ::Virtual('assn_item', QQ::SubSql('select project_id from related_project_assn where child_project_id = {1} and project_id = 1', QQN::Project()->Id))); $this->dtgProjects->DataSource = Project::LoadAll($objClauses); }