salut j'ai fait une code qui s'affiche bien mais j'ai un problème au niveau du calcul du reste de la somme.
au fait un client a une somme totale a payée qui est déjà définie au départ .
il a la possibilité de payer cette somme de façon échelonnée .
je veux :
- afficher les sommes qu'il aura payer
- la somme de ces sommes
- enfin le reste à payer .
je bloque au niveau du calcul du reste
voici mon code :
Code PHP :
<?php
//print_r($_POST);
if(isset($_POST['Ncandidat']) && !empty($_POST['Ncandidat'])){
include("connection.php");
//echo $id=(int)$_POST['Ncandidat'];
$id=(int)$_POST['Ncandidat'];
$id=mysql_real_escape_string($id);
$sql = "SELECT candidat.Ncandidat,candidat.nom,candidat.pieceP,candidat.contact,candidat.nationalite,payement.Npayement,payement.datePay,payement.MTV
FROM candidat,payement
where candidat.Ncandidat = payement.Ncandidat and candidat.Ncandidat='".$id."'";
/*
$query = "SELECT candidat.Ncandidat,candidat.nom,candidat.pieceP,candidat.contact,candidat.nationalite,payement.Npayement,payement.datePay,payement.MTV ".
"FROM candidat, payement ".
"WHERE candidat.Ncandidat = payement.Ncandidat"; */
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$res=null;
while ($liste_etu=mysql_fetch_assoc($req)) {
//$j=$i%2;
$res.='<tr bgcolor=#FFFFCC>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['nom'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['pieceP'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['contact'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['nationalite'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['Npayement'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['datePay'] .'"/></td>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['MTV'] .'"/></td>
</tr>';
}
}else{
$res=null;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
<style type="text/css">
<!--
.Style3 {color: #FFFFFF}
.Style11 {color: #0000FF; font-weight: bold; }
.Style14 {color: #990000}
.Style16 {
color: #000000;
font-weight: bold;
}
.Style17 {font-weight: bold}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p> </p>
<table width="333" border="0" align="center" background="images/Untitled-31.jpg" bgcolor="#FFFFCC">
<tr>
<td bgcolor="#0000FF"><A HREF="bienvenue.php" TITLE="click pour enregistrer vos enfants!!! !!!!" class="Style17 Style3"><strong>Accueil</strong></a></td>
<td bgcolor="#0000FF"> </td>
</tr>
<tr>
<td width="195"><span class="Style16">Numero du Candidat
</span>
<input type="text" name="Ncandidat" /></td>
<td width="128"><input type="submit" name="Submit" value="RECHERCHER" /></td>
</tr>
</table>
</form>
<table width="1306" height="258" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td width="672" height="254"><center>
<fieldset style="width: 1300px;" >
<legend><span class="Style11">RENSEIGNEMENT SUR LE CANDIDAT</span></legend>
<table width="1135" border="0" align="center" cellspacing="1" bordercolor="#333333" bgcolor="#FFFFCC">
<tr bgcolor="#999999">
<th bgcolor="#FFFFCC" scope="row"><div align="left"></div></th>
<td width="208" bgcolor="#FFFFCC"><div align="right"></div></td>
</tr>
<tr bgcolor="#999999">
<th width="132" bgcolor="#FFFFCC" scope="row"><span class="Style14">NOM ET PRENOMS </span></th>
<th width="208" bgcolor="#FFFFCC" scope="row"><span class="Style14">NUMERO DE LA PIECE </span></th>
<th width="107" bgcolor="#FFFFCC" scope="row"><span class="Style14">CONTACT </span></th>
<th width="129" bgcolor="#FFFFCC" scope="row"><span class="Style14">NATIONALITEL </span></th>
<th width="215" bgcolor="#FFFFCC" scope="row"><span class="Style14">NUMERO DE PAYEMENT</span></th>
<th width="196" bgcolor="#FFFFCC" scope="row"><span class="Style14">DATE DE PAEYEMENT</span></th>
<th width="126" bgcolor="#FFFFCC" scope="row"><span class="Style14">VERSEMENT</span></th>
</tr>
<?php
echo $res = isset($res) ? $res : null;
?>
</table>
</fieldset>
</center> </tr>
</table>
<?php
//print_r($_POST);
if(isset($_POST['Ncandidat']) && !empty($_POST['Ncandidat'])){
//include("connection.php");
//echo $id=(int)$_POST['Ncandidat'];
$id=(int)$_POST['Ncandidat'];
$id=mysql_real_escape_string($id);
$sql2 = "SELECT SUM(payement.MTV) AS paye,candidat.montantT
FROM candidat,payement
where candidat.Ncandidat = payement.Ncandidat and candidat.Ncandidat='".$id."'";
/*
$query = "SELECT candidat.Ncandidat,candidat.nom,candidat.pieceP,candidat.contact,candidat.nationalite,payement.Npayement,payement.datePay,payement.MTV ".
"FROM candidat, payement ".
"WHERE candidat.Ncandidat = payement.Ncandidat"; */
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
$res2=null;
while ($liste_etu=mysql_fetch_assoc($req2)) {
//$j=$i%2;
$res2.='<tr bgcolor=#FFFFCC>
<td bgcolor="#CCCCCC"><input type="text" name="textfield" value="'. $liste_etu['paye'] .'"/></td>
</tr>';
}
}else{
$res2=null;
}
echo 'la somme payée est :'.$res2 = isset($res2) ? $res2 : null;
$tot = $liste_etu['montantT'] - $liste_etu['paye'] ;
if($tot == 0){
echo 'vous avez soldé ';
}
else {
echo 'les reste a payé est :'.$tot ;
}
?>
</body>
</html>