1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| try {
$sql = "SELECT id_product, id_user, avg(price) as moy_prix_vente
FROM product_vendu
WHERE date_add >= '2012-12-10' and date_add <= '2012-12-16'
GROUP BY id_product, id_user";
$select = $DB->query($sql);
$select->setFetchMode(PDO::FETCH_OBJ);
if ($row = $select->fetch())
{
$moy1 = $row->moy_prix_vente;
}
} catch ( Exception $e ){
echo "message d'erreur";
}
try {
$sql2 = "SELECT price FROM product_carac
INNER JOIN product_vendu on product_vendu.id_product = product_carac.id_product
WHERE product_vendu.id_product = product_carac.id_product";
$select = $DB->query($sql2);
$select->setFetchMode(PDO::FETCH_OBJ);
if ($row = $select->fetch())
{
$price = $row->price;
}
} catch ( Exception $e ){
echo "message d'erreur";
}
$res = $moy1 / $price;
echo ($res-1)*100; |
Partager