Bonjour,

Code PHP :
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
   try{
    $bdd=new PDO('mysql:host=localhost;dbname=comptebancaire;charset=utf8', 'root','');
    $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);// afficher les erreurs php
}catch(Exception $e){
    die('Erreur :' . $e->getMessage());
}
 
   $response=$bdd->query('SELECT * FROM comptebancaire');
   $saisie=$response->fetchAll();
   $response->closeCursor();
   setlocale(LC_ALL, ['fr_FR.UTF8','fra', 'french']);
   if(isset($_POST['dateoperation'], $_POST['operation'], $_POST['debit'], $_POST['credit'])
    AND !empty($_POST['dateoperation'])
    AND !empty($_POST['operation'])
    AND !empty($_POST['debit'])
    AND !empty($_POST['credit'])
	){
	if(!isset($errors)){
        $saisie =$bdd->prepare("INSERT INTO comptebancaire (dateoperation, operation, debit, credit) VALUES (?,?,?,?)");
		$saisie->execute(array(
			$_POST['dateoperation'],
			$_POST['operation'],
			$_POST['debit'],
			$_POST['credit']
		));
 
		if($saisie->rowCount()>0){//Vérifie si l'opération a bien été ajouté dans la BDD
		    $successMsg = 'L\'opération a bien été ajoutée !';
		}else{
		$errorMsg[]='Suite à un problème dans la base de données, l\'opération n\'a pas pu être ajoutée !';
	    }
	    $response->closeCursor();
    	}
       if(!preg_match('#^[a-zA-Z\-\'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]{50}$#',$_POST['operation'])){
        $errors[] = 'Champ invalide<br>';
        }
        if(!preg_match('#^[0-9]{1,10}([.,][0-9]{1,2})?$#', $_POST['debit'])){
            $errors[] = "Champ invalide";
        }
        if(!preg_match('#^[0-9]{1,3}([.,][0-9]{1,2})?$#', $_POST['credit'])){
            $errors[] = "Champ invalide";
        }
    }
$response = $bdd->query('SELECT * FROM comptebancaire');
$saisie = $response->fetchAll();
 
$response1=$bdd->query('SELECT *, (SELECT SUM(credit-debit) FROM comptebancaire WHERE dateoperation <= ope.dateoperation) AS solde FROM comptebancaire AS ope ORDER BY dateoperation ASC, (credit-debit) DESC');
$solde=$response1->fetch();
$soldecumulee=$solde['solde'];
$response1->closeCursor();
?>
 
<!DOCTYPE html>
<html lang="fr">
 
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/carousel.css">
    <title>Compte bancaire</title>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>
 
<body>
    <div id="listecompte">
        <div class="container">
            <div class="col-sm-12">
                <div class="row">
                    <h1 style="font-size:25px;text-align:center;color:green;">Compte bancaire</h1>
                    <form action="index.php" method="POST">
                        <input type="date" name="dateoperation" placeholder="">
                        <input type="text" name="operation" placeholder="">
                        <input type="text" name="debit" placeholder="">
                        <input type="text" name="credit" placeholder="">
                        <input type="submit">
                    </form><br>
                    <div id="entete">
                        <table>
                            <thead>
                                <tr>
                                    <th id="dateoperation">Date de l'opération</th>
                                    <th id="operation">Opérations</th>
                                    <th id="debit">Débit</th>
                                    <th id="credit">Crédit</th>
                                    <th id="solde">Solde</th>
                                </tr>
                            </thead>
                            <div id="listederoulante">
                                <?php 
                                    if(!empty($saisie)){
                                        foreach($saisie as $data){
                                            $dateoperation = new DateTime($data['dateoperation']);
                                            echo'<tr><td>'.utf8_encode(strftime('%d %B %Y', $dateoperation->format('U'))).'</td><td>'.htmlspecialchars($data['operation']).'</td><td>'.htmlspecialchars($data['debit']).'</td><td>'.htmlspecialchars($data['credit']).'</td><td>'.$soldecumulee.'</td></tr>';
                                            }
                                        }
                                ?>
                            </div>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="application/javascript" src="js/jquery-3.1.1.js"></script>
    <script src="js/script.js"></script>
</body>
 
</html>
Affichage :
Nom : comptebancaire.jpg
Affichages : 1301
Taille : 244,2 Ko

Ce que je souhaite c'est d'avoir un solde cumulé ligne par ligne.

Merci d'avance.