Skip to content

Instantly share code, notes, and snippets.

@tristar500
Created January 13, 2013 15:36
Show Gist options
  • Save tristar500/4524655 to your computer and use it in GitHub Desktop.
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
/**
* 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