Eléphant du PHP |
114 Messages
05 sept. 2005, 10:38
tien je te donne le code de ma page 1 ^^
bonne lecture (

j'ai mis pour toi un peu de commentaire pour que tu puisse relire et comprendre plus facilement !)
car comme c'est une page que je suis actuellement en train de coD je n'ai po toujours le tps de mettre les commentaires en meme temps 8)
le voici
<?php
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
include ("connect.php");
$idr = isset($_POST['categorie'])?$_POST['categorie']:null;
?>
<title>[Administration] Etiquetage1</title>
<style type="text/css">
<!--
.Style13 {font-size: 14px}
.Style20 {font-size: smaller}
.Style23 {font-size: x-small}
-->
</style>
</head>
<body style="font-family: verdana, helvetica, sans-serif; font-size: 85%">
<?php
if(isset($_POST['ok']) && isset($_POST['type']) && $_POST['type'] != "")
{
$cat_selectionnee = $_POST['categorie'];
$type_selectionne = $_POST['type'];
//?>
<?php
}
//<?PHP
// On établit la connexion à MySQL avec mysql_pconnect() plutôt qu'avec mysql_connect()
$connexion = mysql_connect($serveur,$user,$password);
if($connexion != false)
{
$choixbase = mysql_select_db($base, $connexion);
$sql1 = "SELECT `id_cat`, `nom_cat`".
" FROM `categorie`".
" ORDER BY `id_cat`";
$rech_cat = mysql_query($sql1);
$code_cat = array();
$categorie = array();
/* On active un compteur pour les categories */
$nb_cat = 0;
if($rech_cat != false)
{
while($ligne = mysql_fetch_assoc($rech_cat))
{
array_push($code_cat, $ligne['id_cat']);
array_push($categorie, $ligne['nom_cat']);
/* On incrémente de compteur */
$nb_cat++;
}
}
//======================================================================
// Formulaire SELECTION CATEGORIE ET PRODUIT APPARTENANT A LA CATEGORIE
//======================================================================
?>
<br><br>
<!-- TABLEAU REGROUPANT LES LISTE DEROULANTE ET LE BOUTON POST -->
<table width="373" cellpadding=0 cellspacing=0>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgcat">
<!-- Intitulé -->
<tr>
<td class="Style13" ><div> Catégorie :</div></td>
<td ><div class="Style13"> Produits :</div></td>
</tr>
<!-- 1ere liste deroulante -->
<tr>
<td width="185"><select name="categorie" id="categorie" onChange="document.forms['chgcat'].submit();">
<option value="-1">---Choix Catégorie ---</option>
<?php
for($i = 0; $i < $nb_cat; $i++)
{
?>
<option value="<?php echo($code_cat[$i]); ?>"<?php echo((isset($idr) && $idr == $code_cat[$i])?" selected=\"selected\"":null); ?>><?php echo($categorie[$i]." (". $code_cat[$i] .")"); ?></option>
<?php
}
?>
</select></td>
<!-- CODE PHP -->
<?php
mysql_free_result($rech_cat);
/* On commence par vérifier si on a envoyé un numéro de categorie et le cas échéant s'il est différent de -1 */
if(isset($idr) && $idr != -1)
{
/* Cération de la requête pour avoir les produits de cette categorie */
$sql2 = "SELECT `id_type`, `nom_type`".
" FROM `type`".
" WHERE `id_cat` = ". $idr ."".
" ORDER BY `id_type`;";
if($connexion != false)
{
$rech_type = mysql_query($sql2, $connexion);
/* Un petit compteur pour les produits */
$nd = 0;
/* On crée deux tableaux pour les numéros et les noms des produits */
$code_type = array();
$nom_type = array();
/* On va mettre les numéros et noms des produits dans les deux tableaux */
while($ligne_type = mysql_fetch_assoc($rech_type))
{
array_push($code_type, $ligne_type['id_type']);
array_push($nom_type, $ligne_type['nom_type']);
$nd++;
}
?>
<!-- 2eme liste deroulante -->
<td width="187"><select name="type" id="type">
<?php
for($d = 0; $d<$nd; $d++)
{
?>
<option value="<?php echo($code_type[$d]); ?>"<?php echo((isset($type_selectionne) && $type_selectionne == $code_type[$d])?" selected=\"selected\"":null); ?>><?php echo($nom_type[$d]." (". $code_type[$d] .")"); ?></option>
<?php
}
?>
</select></td>
</tr>
<!-- CODE PHP -->
<?php
}
/* Un petit coup de balai */
mysql_free_result($rech_type);
}
?>
<tr>
<td colspan="2"> </td>
</tr>
<!-- Bouton Validation -->
<tr>
<td><input type="submit" name="ok" id="ok" value="Suite >"></td>
</tr>
</form>
</table>
<?php
if(isset($_POST['ok']) && isset($_POST['type']) && $_POST['type'] != "")
{
$cat_selectionnee = $_POST['categorie'];
$type_selectionne = $_POST['type'];
/* Création de la requête pour avoir les produits de cette categorie */
$select = "SELECT id_type, nom_type, ref_type, dureperempt_type, prixht_type FROM type WHERE id_type = ". $type_selectionne ." ;";
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
while($data = mysql_fetch_assoc($result))
{
//?>
<form name="formulaire" action="./etiquetage_nouvprod2.php" method="post" onSubmit="return verif_formulaire()">
<table width="523" cellpadding=0 cellspacing=0>
<tr>
<td width="225" class="Style13"><span class="Style13"><font color="#336699">Nom catégorie : </span></td>
<!-- La requete suivante permet de recuperer le nom de la categorie selectionné -->
<td width="296"><INPUT disabled readonly type="text" size="20" maxlength="20" name="nomcat" value="<?php $selectnom = "SELECT nom_cat FROM categorie WHERE id_cat = ". $cat_selectionnee ." ;";
$resultnom = mysql_query($selectnom) or die ('Erreur : '.mysql_error() );
while($data2 = mysql_fetch_assoc($resultnom))
{
echo $data2['nom_cat'];
}?>" cellspacing=0 cellpadding=0></td>
</tr>
<tr>
<td height="22" class="Style13"><font color="#336699">Nom produit : </td>
<!-- La requete suivante permet de recuperer le nom du produit selectionné -->
<td><INPUT disabled readonly type="text" size="20" maxlength="20" name="nomprod" value="<?php $selectnom = "SELECT nom_type FROM type WHERE id_type = ". $type_selectionne ." ;";
$resultnom = mysql_query($selectnom) or die ('Erreur : '.mysql_error() );
while($data3 = mysql_fetch_assoc($resultnom))
{
echo $data3['nom_type'];
}?>" cellspacing=0 cellpadding=0></td>
</tr>
<td class="Style13"></tr>
<tr>
<td class="Style13"><font color="#336699">Référence :</td>
<td><input disabled readonly type="text" size="10" maxlength="20" name="ref" value="<?php echo $data['ref_type'];?>" cellspacing=0 cellpadding=0></td>
</tr>
<tr>
<td height="18" class="Style13"><font color="#336699">Prix Unitaire HT (kg ou unité) : </td>
<td><input disabled readonly type="text" size="5" maxlength="5" name="prixht" value="<?php echo $data['prixht_type'];?>" cellspacing=0 cellpadding=0>
€ </td>
</tr>
<tr>
<td height="18" class="Style13"> </td>
<td> </td>
</tr>
<tr>
<td class="Style13"><font color="#336699">Date de fabrication :</td>
<td valign="baseline"><input type="text" maxlength="10" size="8" name="datefab" value="jj/mm/aaaa" cellspacing=0 cellpadding=0></td>
</tr>
<tr>
<td class="Style13"><font color="#336699">Date de péremption :</td>
<td><INPUT readonly type="text" size="8" maxlength="10" value="" onClick="mainu(formulaire)" name="dateper" cellspacing=0 cellpadding=0> <img onClick="mainu(formulaire)" align="absmiddle" src="./images/admin/recharger.gif">
</td>
</tr>
<tr>
<td height="23" class="Style13"><span class="Style20"><font color="#336699">Quantité :</span></td>
<td>
<input type="text" id="1" size="1" maxlength="2" name="qtite" value="1" cellspacing=0 cellpadding=0> <IMG
height=10 alt=Ajouter
src="./images/admin/quantite_plus.gif" align="middle" width=14 border=0 onClick="plusOuMoins(1, '+');"> <IMG height=10 alt=Ajouter
src="./images/admin/quantite_moins.gif" align="middle" width=14 border=0 onClick="plusOuMoins(1, '-');">
</td>
</tr>
<tr>
<td class="Style13"><font color="#336699">Poid :</td>
<td><INPUT type="text" size="5" maxlength="5" name="poid" value="<?php echo 'OTO'?>" cellspacing=0 cellpadding=0> Kg</td>
</tr>
<tr>
<td class="Style13"> </td>
<td> </td>
</tr>
<tr>
<td class="Style13"><p class="Style20"><span class="Style13"><font color="#CC6633">Prix Total HT (kg ou unité) </span>:</p>
</td>
<td><INPUT readonly name="prixtot" type="text" id="prixtot" value="" size="5" maxlength="5" onFocus="main(formulaire)" cellspacing=0 cellpadding=0>
€ <img onClick="main(formulaire)" align="absmiddle" src="./images/admin/recharger.gif"></td>
</tr>
<tr>
<td class="Style13"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="button" value="< retour " name="Précédent" onclick="history.back()">
<input name="Envoyer" type="submit" value="Etape Suivante (2/3)"></td>
</tr>
</table>
</form>
<?PHP
}
/* <p>Vous avez sélectionné le produit <?php echo($type_selectionne); ?> de la catégorie <?php echo($cat_selectionnee); ?></p> */
}
/* Terminé, on ferme la connexion */
mysql_close($connexion);
}
?>