For a marketing company, on the personal page of each marketeer I need to output the number of sales (made by the marketeer) from the current week, the commision, which is based on the number of sales made, and the amount of commision a marketeer made (number of sales * commision). Right now I have the following function for the number of sales from the current week:

```
function get_week(){
$sql = "SELECT SUM(sales_made)
FROM marketeer_sales
WHERE marketeer_id = ?
AND WEEKOFYEAR(sales_date) = WEEKOFYEAR(CURDATE())";
$stmt = &this->pdo->prepare($sql);
$stmt->execute(array(1));
$row = $stmt->fetch();
$num_of_sales = $row['SUM(sales_made)'];
return $num_of_sales;
}
```

I have the functions for the commision (get_commision()) and amount (get_deserves()) as well, but in both I am using the exact same query as in the get_week() function and in the get_deserves() function, I even used the values from the get_commision() function, to come to get results as you can see below.

```
function get_commision(){
$sql = "SELECT SUM(sales_made)
FROM marketeer_sales
WHERE marketeer_id = ?
AND WEEKOFYEAR(sales_date) = WEEKOFYEAR(CURDATE())";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array(1));
$row = $stmt->fetch();
$num_of_sales = $row['SUM(sales_made)'];
if ($num_of_sales <= 250){
$commision = "€ 1.50";
}elseif($num_of_sales >= 251 && $num_of_sales <= 500){
$commision = "€ 1.75";
}elseif($num_of_sales >= 501 && $num_of_sales <= 750){
$commision = "€ 2.00";
}elseif($num_of_sales >= 751 && $num_of_sales <= 1000){
$commision = "€ 2.25";
}elseif($num_of_sales >= 1001 && $num_of_sales <= 1250){
$commision = "€ 2.50";
}elseif ($num_of_sales >= 1251){
$commision = "€ 3.00";
}
return $commision;
}
function get_deserves(){
$sql = "SELECT SUM(sales_made)
FROM marketeer_sales
WHERE marketeer_id = ?
AND WEEKOFYEAR(sales_date) = WEEKOFYEAR(CURDATE())";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array(1));
$row = $stmt->fetch();
$num_of_sales = $row['SUM(sales_made)'];
if ($num_of_sales <= 250){
$commision = "€ 1.50";
$deserved = $num_of_sales * $commision;
$deserved = number_format($deserved,2);
}elseif($num_of_sales >= 251 && $num_of_sales <= 500){
$commision = "€ 1.75";
$deserved = $num_of_sales * $commision;
$deserved = number_format($deserved,2);
}...............
etc...........
}
```

This is working but, I’m sure there is a way more effective way, to get the same results by using the values from get_week() in the other two functions, without having to use the same query again but I can’t think of one

Any advise and/or tips would be highly appreciated.

Thank you in advance!