Bonjour à tous ,
j'ai une grande question de débutant
Comme vous le verrez ci dessous, je fais une addition avec une requête. Mais je fais une requête à chaque fois que le nom change ...
Cela fonctionne très bien , mais je demande :
- est il possible de faire plus simple ?
- ce type de code ne va pas encombré MYSQL inutilement ?
Un grand merci !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 $sql2 = $base->query("SELECT SUM(montant) AS loyer FROM $table1 WHERE id_bien='$bien_id'AND nom= 40 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : des loyers est de " .$somme['loyer']. " <h6> </td> </th> "; $loyer = $somme['loyer']; } $sql2 = $base->query("SELECT SUM(montant) AS apl FROM $table1 WHERE id_bien='$bien_id'AND nom= 190 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : des apl est de " .$somme['apl']. " <h6> </td> </th> "; $apl =$somme['apl']; } $sql2 = $base->query("SELECT SUM(montant) AS foncier FROM $table1 WHERE id_bien='$bien_id'AND nom= 50 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : des foncier est de " .$somme['foncier']. " <h6> </td> </th> "; $foncier =$somme['foncier']; } $sql2 = $base->query("SELECT SUM(montant) AS compte FROM $table1 WHERE id_bien='$bien_id'AND nom= 170 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : frais de compte est de " .$somme['compte']. " <h6> </td> </th> "; $compte =$somme['compte']; } $sql2 = $base->query("SELECT SUM(montant) AS hab FROM $table1 WHERE id_bien='$bien_id'AND nom= 60 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : de la assurance habitation est de " .$somme['hab']. " <h6> </td> </th> "; $hab =$somme['hab']; } $sql2 = $base->query("SELECT SUM(montant) AS impaye FROM $table1 WHERE id_bien='$bien_id'AND nom= 70 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : de la taxe assurance loyer impaye est de " .$somme['impaye']. " <h6> </td> </th> "; $impaye =$somme['impaye']; } $sql2 = $base->query("SELECT SUM(montant) AS emprunteur FROM $table1 WHERE id_bien='$bien_id'AND nom= 140 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : assurance emprunteur est de " .$somme['emprunteur']. " <h6> </td> </th> "; $emprunteur =$somme['emprunteur']; } $sql2 = $base->query("SELECT SUM(montant) AS credit FROM $table1 WHERE id_bien='$bien_id'AND nom= 80 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : de votre crédit est de " .$somme['credit']. " <h6> </td> </th> "; $credit =$somme['credit']; } $sql2 = $base->query("SELECT SUM(montant) AS interet FROM $table1 WHERE id_bien='$bien_id'AND nom= 90 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : le montant des interets est de " .$somme['interet']. " <h6> </td> </th> "; $interet =$somme['interet']; } $sql2 = $base->query("SELECT SUM(montant) AS travaux FROM $table1 WHERE id_bien='$bien_id'AND nom= 100 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : travaux est de " .$somme['travaux']. " <h6> </td> </th> "; $travaux =$somme['travaux']; } $sql2 = $base->query("SELECT SUM(montant) AS syndics FROM $table1 WHERE id_bien='$bien_id'AND nom= 160 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : syndics est de " .$somme['syndics']. " <h6> </td> </th> "; $syndics =$somme['syndics']; } $sql2 = $base->query("SELECT SUM(montant) AS charge_recu FROM $table1 WHERE id_bien='$bien_id'AND nom= 10 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : charges perçus est de " .$somme['charge_recu']. " <h6> </td> </th> "; $charge_recu =$somme['charge_recu']; } $sql2 = $base->query("SELECT SUM(montant) AS charge_paye FROM $table1 WHERE id_bien='$bien_id'AND nom= 20 "); $somme = $sql2->fetch(PDO::FETCH_ASSOC); { echo "<th> <td colspan = 5 > <h6> Le total des : des charges payées par le propriétaire est de " .$somme['charge_paye']. " <h6> </td> </th> "; $charge_paye =$somme['charge_paye']; }
Partager