Created
January 13, 2013 15:36
-
-
Save tristar500/4524655 to your computer and use it in GitHub Desktop.
MySql to select progress data and return steps, completed, not_completed and progress
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
/** | |
* Return the goal step progress values | |
* @param int $id the goal id | |
* @return object contains goal step completion data | |
*/ | |
public static function progress($id) | |
{ | |
$query = "SELECT | |
COUNT(completed) as total, | |
COUNT(if(completed=1, 1, null)) as completed, | |
COUNT(if(completed=0, 1, null)) as not_completed, | |
(COUNT(if(completed=1, 1, null)) / COUNT(completed) * 100) as progress | |
FROM steps | |
WHERE id_goal = '$id'"; | |
return DB::query($query); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment