Here is my SQL code. I have selected the price of each row and the milestone of each row and the id to join the tables, but I have only the result of one row.
PHP code to do multiple filters:
if($i==0)
{
if($fc == "projet")
{
$filtre_bdd .= "AND p.$fc = '$fv' ";
}
else
{
$filtre_bdd .= "AND cible.$fc = '$fv' ";
$i= $i + 2;
}
}
SQL query:
SELECT cible.prix,a.valeur,a.idroute,cible.id,p.id,
SUM(DISTINCT a.valeur) AS total_avances, /* the milestone sum the unique one */
SUM(a.valeur) AS total_avance, /* the milestone sum of each row */
SUM(cible.prix) AS total_prix /* the price sum */
FROM avances AS a,routes AS cible,projets AS p
WHERE a.idroute = cible.id AND p.id = cible.idprojet $filtre_bdd /* the conditions to join the tables and do the filter */
GROUP BY cible.id, a.idroute
HAVING total_avances <> cible.prix AND cible.prix - total_avances >- 1
Now how can I get the totals of the prices and the total of the milestones with all those conditions? The targeted table contains the id of the project and the id of the milestones. We have to do the sum of the milestones for each row and sum of the sums and compare it to the project price.