$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);
}
?>



<?php 
require '../includes/footer.inc.php';
Example #2
0
    public static function LoadArrayByMinimumId($intId, $strOrderBy = null, $strLimit = null, $objExpansionMap = null)
    {
        // Call to ArrayQueryHelper to Get Database Object and Get SQL Clauses
        Project::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase);
        // Escape the Parameter(s)
        $intId = $objDatabase->SqlVariable($intId);
        // Setup the SQL Query
        $strQuery = sprintf('
				SELECT
				%s
					project.*
					%s
				FROM
					`project` AS `project`
					%s
				WHERE
					project.id > %s
				%s
				%s', $strLimitPrefix, $strExpandSelect, $strExpandFrom, $intId, $strOrderBy, $strLimitSuffix);
        // Perform the Query and Instantiate the Result
        $objDbResult = $objDatabase->Query($strQuery);
        return Project::InstantiateDbResult($objDbResult);
    }
Example #3
0
?>
	Updated.  (Use <b>View Source</b> above to see the code for this)



	<h3>Custom Load Query: Select all Projects with Budgets over $5000, ordered by Descending Budget</h3>
<?php 
// Custom Load Queries must have a resultset that returns all the fields of the
// table which corresponds to the ORM class you want to instantiate
// Note that because the InstantiateDb* methods in your ORM classes are code generated
// it is actually safe to use "SELECT *" for your Custom Load Queries.
$strQuery = 'SELECT project.* FROM project WHERE budget > 5000 ORDER BY budget DESC';
// perform the query
$objDbResult = $objDatabase->Query($strQuery);
// Use the Project::InstantiateDbResult on the $objDbResult to get an array of Project objects
$objProjectArray = Project::InstantiateDbResult($objDbResult);
// Iterate through the Project Array as you would any other ORM object
foreach ($objProjectArray as $objProject) {
    _p($objProject->Name . ' has a budget of $' . $objProject->Budget);
    _p('<br/>', false);
}
?>



	<h3>Qcodo Query: Select all Projects which have a Budget over $5000 and under $10000, ordered by Descending Budget</h3>
<?php 
// Perform the Query using Project::QueryArray, which will return an array of Project objects
// given a QQ Condition, and any optional QQ Clauses.
$objProjectArray = Project::QueryArray(QQ::AndCondition(QQ::GreaterThan(QQN::Project()->Budget, 5000), QQ::LessThan(QQN::Project()->Budget, 10000)), QQ::Clause(QQ::OrderBy(QQN::Project()->Budget, false)));
// Iterate through the Project Array like last time