par
donny » 21 juin 2005, 10:18
si quelqu un voi un ce que je veux faire voila mon code
mais je doute que sa vienne quand je saisi un nouvel enregistrement, il est mis dans le tableau mais vu qu il faut charger la page pour remplir le tableau alimenter dans la liste deroulante des bon de commande, alors il y a un temps de decallage ce qui explique pourquoi sa ne fonctionne pas au premier coup. ?
<?php
session_start();
?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function effacer()
{
document.acheter.cmd.value="";
document.acheter.fourn.value="";
document.acheter.numcom.value="";
document.acheter.date1.value="<? echo date("d/m/Y"); ?>";
}
</SCRIPT>
</head>
<body>
<?php
// on se connecte a postgres
include("connexion.inc.php");
//if (isset($_GET['numserie'])){
//$_SESSION['seri']=$_GET['numserie'];
//}
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" name="acheter" method="GET">
<? if(!isset($_GET['max']))
{
$result = pg_query("select distinct(boncommande),date,numfournisseur from acheter order by boncommande");
$max = pg_num_rows($result) - 1;//la numérotaion commence à 0
$suivant = 1;
$precedent = -1;
$id = 0;
}
else
{
$max = intval($_GET['max']);
$id = intval($_GET['id']);
$suivant = $id + 1;
$precedent = $id - 1;
}
$sql="select distinct(boncommande),date,numfournisseur from acheter order by boncommande LIMIT 1 OFFSET " . $id;
$result = pg_query($sql) or die('erreur');
$row = pg_fetch_row($result);
if(isset($_GET['id']))
{
$_SESSION['id']=$id;
}
else
{
$_SESSION['id']=$id;
}
$_SESSION['max']=$max;
echo " L ID est : ".$_SESSION['id']."<br>";
echo " Le max est : ".$_SESSION['max'];
?>
<table>
<tr>
<?//<input type="hidden" name="t1" value="<?php echo $row[0]; ?>"> ?>
<td><i>Bon commande</i></td>
<td><select name="cmd" onChange="location.href='<?php echo $_SERVER['PHP_SELF'] ;?>?max=' + <? echo $_SESSION['max']; ?> + '&id='+ this.value;alert(this.options[this.selectedIndex].text); ">
<?
$j=0;
$liste_etat = array();
$sql1="select distinct(boncommande) from acheter order by boncommande";
$res1=pg_query($sql1);
while($list1=pg_fetch_array($res1))
{
?>
<option value="<? echo $j; ?>" <? if($list1['boncommande'] == $row[0]){echo(" selected=\"selected\"");}?> id="<? echo $j ; ?>" ><? echo $list1['boncommande']; ?></option>
<?
$liste_etat[$j]=$list1['boncommande'];
$j++;
}
?>
</select>
</td>
<td><i>Date</i></td>
<td><input type="text" name="date1" value="<?php echo date('d/m/Y', strtotime($row[1])); ?>" /></td>
</tr>
<tr>
<td><i>Bon commande</i></td>
<td><input type="text" name="numcom" value="<?php echo $liste_etat[$id]; $_SESSION['cd']=$liste_etat[$id];?>"></td>
<? echo "<h1> Bon co ".$_SESSION['cd']."</h1>"; ?>
</tr>
<tr>
<td><i>Fournisseur</i></td>
<td><select name="fourn">
<?
$sql1="select societe,numfournisseur from fournisseurs order by societe";
$res1=pg_query($sql1);
while($list1=pg_fetch_array($res1))
{
?>
<option value="<? echo $list1['numfournisseur']; ?>" <? if($list1['numfournisseur'] == $row[2]){echo(" selected=\"selected\"");}?>><? echo $list1['societe']; ?></option>
<?
}
?>
</select>
</td>
</tr>
</table>
<?php $deb=$max-$max;
echo "<a href=\"acheter.php?max=" . $max . "&id=" . $deb . "\">DEBUT</a> ";
if($precedent != -1)
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $precedent . "\">PRECEDENT</a> ";
if($suivant <= $max)
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $suivant . "\">SUIVANT</a> ";
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $max . "\">FIN</a> ";
?>
<br>
<br>
<input type="submit" name="Modifier" value="Modifier" onclick=" return confirm('Vraiment modifier?')">
<input type="submit" name="mab" value="Effacer" >
<input type="submit" name="Nouveau" value="Nouveau" onclick=" return confirm('Vraiment enregistrer?')">
<? if(isset($_GET['mab']))
{
echo "<script>javascript:effacer();</script>";
}
if(!isset($_GET['mab']))
{
$sql="select refcontructeur,date,acheter.quantite,prix from acheter,consommable where consommable.numconso=acheter.numconso and boncommande ='".$row[0]."' order by boncommande ";
echo $sql;
$res=pg_query($sql);
?>
<table border="1" >
<tr>
<th style="display:none">a</th>
<th style="display:none">b</th>
<th>Consommable</th>
<th>Date</th>
<th>Quantite</th>
<th>Prix</th>
</tr>
<?
$i=0;
while($list=pg_fetch_array($res))
{
?>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td><? echo $list['refcontructeur']; ?></td>
<td><? echo date('d/m/Y', strtotime($list['date'])); ?></td>
<td><? echo $list['quantite']; ?></td>
<td><? echo $list['prix']; ?></td>
</tr>
<?
$i=$i+1;
}
?>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td>
<select name="ref">
<?
$sql="select numconso,refcontructeur from consommable order by refcontructeur";
$result=pg_query($sql);
while($list=pg_fetch_array($result)){
?>
<option value="<? echo $list['numconso']; ?>" ><? echo $list['refcontructeur'] ;?></option>
<?
}
?>
</select>
</td>
<td><input type="text" name="datec" value="<? echo date("d/m/Y"); ?>"></td>
<td><input type="text" name="quantitec" value=""></td>
<td><input type="text" name="prixc" value=""></td>
</tr>
</table>
<?
}
else
{
?>
<table border="1" >
<tr>
<th style="display:none">a</th>
<th style="display:none">b</th>
<th>Consommable</th>
<th>Date</th>
<th>Quantite</th>
<th>Prix</th>
</tr>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td>
<select name="ref">
<?
$sql="select numconso,refcontructeur from consommable order by refcontructeur";
$result=pg_query($sql);
while($list=pg_fetch_array($result)){
?>
<option value="<? echo $list['numconso']; ?>" ><? echo $list['refcontructeur'] ;?></option>
<?
}
?>
</select>
</td>
<td><input type="text" name="datec" value="<? echo date("d/m/Y"); ?>"></td>
<td><input type="text" name="quantitec" value=""></td>
<td><input type="text" name="prixc" value=""></td>
</tr>
</table>
<?
}
?>
<br>
<br>
<input type="submit" name="ajout" value="Ajouter" >
<input type="submit" name="zz" value="zz">
<?
if(isset($_GET['zz']))
{
if(isset($_GET['numcom']))
{
$_SESSION['com']=$_GET['numcom'];
}
echo "<h1>".$_SESSION['com']."</h1>";
$sql="insert into acheter ( numfournisseur,numconso,boncommande, date,quantite,prix) values ( ".$_GET['fourn'].", ".$_GET['ref'].", '".$_GET['numcom']."','".$_GET['datec']."',".$_GET['quantitec'].",".$_GET['prixc'].")";
echo "<b>".$sql."</b>";
$result=pg_query($sql);
if($result)
{
echo "<script>alert('Insertion reussi !');</script>";
}else{
echo "<script>alert('Echec Insertion !');</script>";
}
for($p=0; $p<count($liste_etat); $p++)
{
if($liste_etat[$p]==$_SESSION['com'])
{
$z=$p;
$z2=$liste_etat[$p];
$_SESSION['id2']=$z;
}
}
echo "p = ".$z;
echo "comm = ".$z2;
//echo "<h1>".$_SESSION['id2']."</h1>";
echo "<script>javascript:location.href='".$_SERVER['PHP_SELF']."?max=' + ".$_SESSION['max']." + '&id='+ ".$_SESSION['id2']."</script>";
}
echo "p = ".$z;
echo "comm = ".$_SESSION['id2'];
?>
<?
echo count($liste_etat);
for($p=0; $p<count($liste_etat); $p++)
{
echo "resu : ".$p." = ".$liste_etat[$p]."<br>";
if($liste_etat[$p]==$_SESSION['com']){
echo "<h2>".$liste_etat[$p]."</h2>";
echo "<b> Le p = ".$p."</b>";
}
}
?>
</form>
</body>
</html>
si quelqu un voi un ce que je veux faire voila mon code
mais je doute que sa vienne quand je saisi un nouvel enregistrement, il est mis dans le tableau mais vu qu il faut charger la page pour remplir le tableau alimenter dans la liste deroulante des bon de commande, alors il y a un temps de decallage ce qui explique pourquoi sa ne fonctionne pas au premier coup. ?
[php]<?php
session_start();
?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function effacer()
{
document.acheter.cmd.value="";
document.acheter.fourn.value="";
document.acheter.numcom.value="";
document.acheter.date1.value="<? echo date("d/m/Y"); ?>";
}
</SCRIPT>
</head>
<body>
<?php
// on se connecte a postgres
include("connexion.inc.php");
//if (isset($_GET['numserie'])){
//$_SESSION['seri']=$_GET['numserie'];
//}
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" name="acheter" method="GET">
<? if(!isset($_GET['max']))
{
$result = pg_query("select distinct(boncommande),date,numfournisseur from acheter order by boncommande");
$max = pg_num_rows($result) - 1;//la numérotaion commence à 0
$suivant = 1;
$precedent = -1;
$id = 0;
}
else
{
$max = intval($_GET['max']);
$id = intval($_GET['id']);
$suivant = $id + 1;
$precedent = $id - 1;
}
$sql="select distinct(boncommande),date,numfournisseur from acheter order by boncommande LIMIT 1 OFFSET " . $id;
$result = pg_query($sql) or die('erreur');
$row = pg_fetch_row($result);
if(isset($_GET['id']))
{
$_SESSION['id']=$id;
}
else
{
$_SESSION['id']=$id;
}
$_SESSION['max']=$max;
echo " L ID est : ".$_SESSION['id']."<br>";
echo " Le max est : ".$_SESSION['max'];
?>
<table>
<tr>
<?//<input type="hidden" name="t1" value="<?php echo $row[0]; ?>"> ?>
<td><i>Bon commande</i></td>
<td><select name="cmd" onChange="location.href='<?php echo $_SERVER['PHP_SELF'] ;?>?max=' + <? echo $_SESSION['max']; ?> + '&id='+ this.value;alert(this.options[this.selectedIndex].text); ">
<?
$j=0;
$liste_etat = array();
$sql1="select distinct(boncommande) from acheter order by boncommande";
$res1=pg_query($sql1);
while($list1=pg_fetch_array($res1))
{
?>
<option value="<? echo $j; ?>" <? if($list1['boncommande'] == $row[0]){echo(" selected=\"selected\"");}?> id="<? echo $j ; ?>" ><? echo $list1['boncommande']; ?></option>
<?
$liste_etat[$j]=$list1['boncommande'];
$j++;
}
?>
</select>
</td>
<td><i>Date</i></td>
<td><input type="text" name="date1" value="<?php echo date('d/m/Y', strtotime($row[1])); ?>" /></td>
</tr>
<tr>
<td><i>Bon commande</i></td>
<td><input type="text" name="numcom" value="<?php echo $liste_etat[$id]; $_SESSION['cd']=$liste_etat[$id];?>"></td>
<? echo "<h1> Bon co ".$_SESSION['cd']."</h1>"; ?>
</tr>
<tr>
<td><i>Fournisseur</i></td>
<td><select name="fourn">
<?
$sql1="select societe,numfournisseur from fournisseurs order by societe";
$res1=pg_query($sql1);
while($list1=pg_fetch_array($res1))
{
?>
<option value="<? echo $list1['numfournisseur']; ?>" <? if($list1['numfournisseur'] == $row[2]){echo(" selected=\"selected\"");}?>><? echo $list1['societe']; ?></option>
<?
}
?>
</select>
</td>
</tr>
</table>
<?php $deb=$max-$max;
echo "<a href=\"acheter.php?max=" . $max . "&id=" . $deb . "\">DEBUT</a> ";
if($precedent != -1)
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $precedent . "\">PRECEDENT</a> ";
if($suivant <= $max)
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $suivant . "\">SUIVANT</a> ";
echo " <a href=\"acheter.php?max=" . $max . "&id=" . $max . "\">FIN</a> ";
?>
<br>
<br>
<input type="submit" name="Modifier" value="Modifier" onclick=" return confirm('Vraiment modifier?')">
<input type="submit" name="mab" value="Effacer" >
<input type="submit" name="Nouveau" value="Nouveau" onclick=" return confirm('Vraiment enregistrer?')">
<? if(isset($_GET['mab']))
{
echo "<script>javascript:effacer();</script>";
}
if(!isset($_GET['mab']))
{
$sql="select refcontructeur,date,acheter.quantite,prix from acheter,consommable where consommable.numconso=acheter.numconso and boncommande ='".$row[0]."' order by boncommande ";
echo $sql;
$res=pg_query($sql);
?>
<table border="1" >
<tr>
<th style="display:none">a</th>
<th style="display:none">b</th>
<th>Consommable</th>
<th>Date</th>
<th>Quantite</th>
<th>Prix</th>
</tr>
<?
$i=0;
while($list=pg_fetch_array($res))
{
?>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td><? echo $list['refcontructeur']; ?></td>
<td><? echo date('d/m/Y', strtotime($list['date'])); ?></td>
<td><? echo $list['quantite']; ?></td>
<td><? echo $list['prix']; ?></td>
</tr>
<?
$i=$i+1;
}
?>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td>
<select name="ref">
<?
$sql="select numconso,refcontructeur from consommable order by refcontructeur";
$result=pg_query($sql);
while($list=pg_fetch_array($result)){
?>
<option value="<? echo $list['numconso']; ?>" ><? echo $list['refcontructeur'] ;?></option>
<?
}
?>
</select>
</td>
<td><input type="text" name="datec" value="<? echo date("d/m/Y"); ?>"></td>
<td><input type="text" name="quantitec" value=""></td>
<td><input type="text" name="prixc" value=""></td>
</tr>
</table>
<?
}
else
{
?>
<table border="1" >
<tr>
<th style="display:none">a</th>
<th style="display:none">b</th>
<th>Consommable</th>
<th>Date</th>
<th>Quantite</th>
<th>Prix</th>
</tr>
<tr class="white" onClick="blok(this, 'radio<? echo $i ; ?>','radio2<? echo $i ; ?>' )">
<td style="display:none"><input type="radio" name="a" id="radio<? echo $i ;?>" value="<? echo $list['numserie'];?>"></td>
<td style="display:none"><input type="radio" name="b" id="radio2<? echo $i ;?>" value="<? echo $list['etat'];?>"></td>
<td>
<select name="ref">
<?
$sql="select numconso,refcontructeur from consommable order by refcontructeur";
$result=pg_query($sql);
while($list=pg_fetch_array($result)){
?>
<option value="<? echo $list['numconso']; ?>" ><? echo $list['refcontructeur'] ;?></option>
<?
}
?>
</select>
</td>
<td><input type="text" name="datec" value="<? echo date("d/m/Y"); ?>"></td>
<td><input type="text" name="quantitec" value=""></td>
<td><input type="text" name="prixc" value=""></td>
</tr>
</table>
<?
}
?>
<br>
<br>
<input type="submit" name="ajout" value="Ajouter" >
<input type="submit" name="zz" value="zz">
<?
if(isset($_GET['zz']))
{
if(isset($_GET['numcom']))
{
$_SESSION['com']=$_GET['numcom'];
}
echo "<h1>".$_SESSION['com']."</h1>";
$sql="insert into acheter ( numfournisseur,numconso,boncommande, date,quantite,prix) values ( ".$_GET['fourn'].", ".$_GET['ref'].", '".$_GET['numcom']."','".$_GET['datec']."',".$_GET['quantitec'].",".$_GET['prixc'].")";
echo "<b>".$sql."</b>";
$result=pg_query($sql);
if($result)
{
echo "<script>alert('Insertion reussi !');</script>";
}else{
echo "<script>alert('Echec Insertion !');</script>";
}
for($p=0; $p<count($liste_etat); $p++)
{
if($liste_etat[$p]==$_SESSION['com'])
{
$z=$p;
$z2=$liste_etat[$p];
$_SESSION['id2']=$z;
}
}
echo "p = ".$z;
echo "comm = ".$z2;
//echo "<h1>".$_SESSION['id2']."</h1>";
echo "<script>javascript:location.href='".$_SERVER['PHP_SELF']."?max=' + ".$_SESSION['max']." + '&id='+ ".$_SESSION['id2']."</script>";
}
echo "p = ".$z;
echo "comm = ".$_SESSION['id2'];
?>
<?
echo count($liste_etat);
for($p=0; $p<count($liste_etat); $p++)
{
echo "resu : ".$p." = ".$liste_etat[$p]."<br>";
if($liste_etat[$p]==$_SESSION['com']){
echo "<h2>".$liste_etat[$p]."</h2>";
echo "<b> Le p = ".$p."</b>";
}
}
?>
</form>
</body>
</html>
[/php]