Aller au contenu

nas13190

Membre
  • Compteur de contenus

    2
  • Inscrit(e) le

  • Dernière visite

Réputation sur la communauté

0 Neutre
  1. Arf j'aurai du tourner sept fois ma langue dans ma bouche avant de poster... L'erreur provenait du fait que je faisais un include après ma requète or dans cet include on retrouvait des valeurs ($query, $result) identiques qui remplaçaient celles du formulaire rendant mon fetch_array NULL.... Enfin bon une bonne leçon concernant l'appellation et la manipulation de variables
  2. Bonjour, Ayant remarqué les réponses éclairées sur différents posts je me suis inscrit pour vous exposer mon soucis et ainsi m'en remettre à vos savoirs : Voilà le soucis, j'ai un formulaire banal (testé en method="POST" et method="GET") en retour de ce formulaire, lorsqu'il est validé il nous retourne un 'id' qui me permettra, comme tout id qui se respecte, de rechercher une entrée unique dans ma BDD sql. Jusque là tout va bien, l'id est transmis (en method="GET" j'ai bien index.php?visualiser=&id=XX) Mais dans ma page de réponse (celle qui est lancée lorsqu'on valide le formulaire) mon $id = $_GET['id'] ; (ou $id = $_POST['id'] ; si on utilise la methode POST dans le formulaire) me retourne peenuts... Alors à tout hazard je poste mon code : Formulaire : <?php include ('menu_gauche.php') ; // --------------------------------------------------------------------------------------------------------------------- // La base de donnees (voiturexpo) avec une table (matable) // La table doit contenir (au moins) les champs suivants : // - NUM (INT - 11 - auto-incremente - NotNull) // - COMMENT1 (VARCHAR - 255 - Null) // - PHOTO1 (VARCHAR - 255 - Null) // - PICTO1 (VARCHAR - 255 - Null) // Important : conserver le champ COMMENT1, il est necessaire en mode AJOUTER // --------------------------------------------------------------------------------------------------------------------- // Les photos et pictos sont stockes dans un dossier deprotege en ecriture $chemincourt = 'annonces/img/'; // --------------------------------------------------------------------------------------------------------------------- // Fonction recherche // Affichage de 5 annonces par page $nb_results_p_page = 5; // nombre de résultats par page $courant = empty($_GET['page']) ? 1 : $_GET['page']; // page $start = ($courant - 1) * $nb_results_p_page ; // start (requete mysql) if(isset($_GET['mot_recherche']) && $_GET['mot_recherche'] != '' ) { $mot_recherche = $_GET['mot_recherche'] ; $cat_recherche = $_GET['cat_recherche'] ; if($cat_recherche == 'modele_marque') { $query_recherche = "SELECT * from matable where promo='oui' and marque like '%".$mot_recherche."%' OR modele like '%".$mot_recherche."%' LIMIT $start, $nb_results_p_page" ; $liste = mysql_query($query_recherche) or die('Erreur SQL ! '.$query_recherche.'<br/>'.mysql_error()); // echo $liste ; $result = mysql_query("SELECT count(NUM) from matable where promo='oui' and marque like '%".$mot_recherche."%' OR modele like '%".$mot_recherche."%'") ; } elseif($cat_recherche == 'prix') { $mot_recherche = intval($mot_recherche) ; $query_recherche = "SELECT * from matable where promo='oui' and prix <= '".$mot_recherche."' LIMIT $start, $nb_results_p_page" ; $liste = mysql_query($query_recherche) or die('Erreur SQL ! '.$query_recherche.'<br/>'.mysql_error()); // echo $liste ; $result = mysql_query("SELECT count(NUM) from matable where promo='oui' and prix <= '".$mot_recherche."'") ; } else // Si rien c'est que c'est annee qui a été sélectionné { $query_recherche = "SELECT * from matable where promo='oui' and annee >= '".$mot_recherche."' LIMIT $start, $nb_results_p_page" ; $liste = mysql_query($query_recherche) or die('Erreur SQL ! '.$query_recherche.'<br/>'.mysql_error()); // echo $liste ; $result = mysql_query("SELECT count(NUM) from matable where promo='oui' and annee >= '".$mot_recherche."'") ; } } else { $query_recherche = "SELECT * from matable where promo='oui' order by prix LIMIT $start, $nb_results_p_page" ; $liste = mysql_query($query_recherche) ; // echo $liste ; $result = mysql_query("SELECT count(NUM) from matable where promo='oui' order by prix") ; } ?> <!-- START : content --> <div id="content"> <div class="top"><h2>Offres promotionnelles</h2></div> <div class="middle"> <p> <table id="56" align="center"> <tr> <form name="recherche" method="GET" action="index.php"> <td> <input type="text" name="mot_recherche"> </td> <td> <select name="cat_recherche"> <option selected value="modele_marque">-> Marque ou Modèle -></option> <option value="annee">-> Année minimum -></option> <option value="prix">-> Prix maximum -></option> </select> </td> <td> <input type="submit" value="Rechercher"> <input type="hidden" name="recherche"> <input type="hidden" name="page" value="1"> </td> </form> </tr> </table> <table id="58"> <tr> <td colspan="6"> <?php include ('affichage_par_page.php') ; echo '<br>Nombre d\'annonces : <b>'.$nb_results.'</b>' ?> </td> </tr> </table> <table id="62" border="1"> <tr> <th width="15%">Photos</th> <th width="15%">Marque</th> <th width="15%">Modèle</th> <th width="15%">Année</th> <th width="15%">Prix</th> <th width="25%">Informations</th> </tr> <?php while($row=mysql_fetch_array($liste)) { echo '<tr>' ; ?> <td> <p align="center"> <?php if ($row['PICTO1'] != "") { ?><img alt="" border="0" src="<?php echo $chemincourt.$row['PICTO1']; ?>" <?php fctaffichimage(50, 50, $chemincourt.$row['PICTO1']) ?>><?php } else { ?> <?php }?> </p> </td> <td> <p align="center"> <font face="Tahoma" color="#003300"> <?php echo $row['marque'] ; ?> </font> </p> </td> <?php if ($row['promo'] == 'oui') {echo "<td bgcolor = '#FF0F3F'>"; } else {echo "<td>"; } ?> <p align="center"> <font face="Tahoma" color="#003300"> <?php echo $row['modele'] ; ?> </font> </p> </td> <td> <p align="center"> <font face="Tahoma" color="#003300"> <?php echo $row['annee'] ; ?> </font> </p> </td> <td> <p align="center"> <font face="Tahoma" color="#003300"> <?php echo $row['prix']." Euros" ; ?> </font> </p> </td> <td align="center" valign="middle"> <form name="visualiser" method="GET" action="index.php"> <input type="submit" value="Plus de détails"> <input type="hidden" name="visualiser"> <input type="hidden" name="id" value="<?php echo $row['NUM'] ;?>"><br> <font size="1"><b>Et voir les photos plus grandes - <?php echo $row['NUM'] ;?></b></font> </form> </td> <?php } ?> </tr> </table> </p><br /> </div> <div class="bottom"></div> </div> <!-- END : content --> Page réponse après validation du formulaire : <?php // Récupération du NUM de l'annonce (identifiant unique) $id = $_GET['id'] ; // recuperation des donnees de la fiche pour affichage $query = 'SELECT * FROM matable WHERE NUM = '. $id; $result = mysql_query($query) or die('Erreur SQL ! '.$query.'<br/>'.mysql_error()); $val = mysql_fetch_array($result); include ('menu_gauche.php') ; ?> <!-- START : content --> <div id="content"> <div class="top"><h2>Annonce</h2></div> <div class="middle"> <p> <table> <tr> <td colspan="2"> <u><b>Informations concernant le véhicule - Annonce numéro : <?php echo $val['NUM']; ?></b></u> </td> </tr> <tr> <td> Marque : </td> <td> <?php echo $val['marque']; ?> </td> </tr> <tr> <td> Modèle : </td> <td> <b><?php echo $val['modele']; ?></b> </td> </tr> <tr> <td> Dénomination : </td> <td> <?php echo $val['denomin']; ?> </td> </tr> <tr> <td> Kilométrage : </td> <td> <?php echo $val['kms']; ?> Kms </td> </tr> <tr> <td> Description : </td> <td> <?php echo $val['descrip'] ; ?> </td> </tr><?php if ($val['promo'] =='oui') { ?><tr> <td> Promotion : </td> <td> <?php echo $val['promo']; ?> </td> </tr><?php } ?><tr> <td> Garantie : </td> <td> <?php echo $val['garantie']; ?> Mois </td> </tr> <tr> <td> Prix : </td> <td> <b><?php echo $val['prix'] ;?> Euros</b> </td> </tr> </table> <table align="center" valign="middle"> <tr align="center" valign="middle"> <tr align="center"> <td> <br><br><u><b>Photos</b></u> </td> </tr> <?php if(isset($val['PHOTO1']) or isset($val['PHOTO2']) or isset($val['PHOTO3']) or isset($val['PHOTO4']) or isset($val['PHOTO5'])) { if(isset($val['PHOTO1'])) { ?><td width="110"><a href="annonces/img/<?php echo $val['PHOTO1'] ; ?>" rel="lightbox[roadtrip]" title="<?php echo $val['COMMENT1'] ; ?>" ><img src="annonces/img/<?php echo $val['PHOTO1'] ; ?>" width="80" height="80" alt="<?php echo $val['COMMENT1'] ; ?>" /></a></td> <?php } if(isset($val['PHOTO2'])) { ?><td width="110"><a href="annonces/img/<?php echo $val['PHOTO2'] ; ?>" rel="lightbox[roadtrip]" title="<?php echo $val['COMMENT2'] ; ?>"><img src="annonces/img/<?php echo $val['PHOTO2'] ; ?>" width="80" height="80" alt="<?php echo $val['COMMENT2'] ; ?>" /></a></td> <?php } if(isset($val['PHOTO3'])) { ?><td width="110"><a href="annonces/img/<?php echo $val['PHOTO3'] ; ?>" rel="lightbox[roadtrip]" title="<?php echo $val['COMMENT3'] ; ?>"><img src="annonces/img/<?php echo $val['PHOTO3'] ; ?>" width="80" height="80" alt="<?php echo $val['COMMENT3'] ; ?>" /></a></td> <?php } if(isset($val['PHOTO4'])) { ?><td width="110"><a href="annonces/img/<?php echo $val['PHOTO4'] ; ?>" rel="lightbox[roadtrip]" title="<?php echo $val['COMMENT4'] ; ?>"><img src="annonces/img/<?php echo $val['PHOTO4'] ; ?>" width="80" height="80" alt="<?php echo $val['COMMENT4'] ; ?>" /></a></td> <?php } if(isset($val['PHOTO5'])) { ?><td width="110"><a href="annonces/img/<?php echo $val['PHOTO5'] ; ?>" rel="lightbox[roadtrip]" title="<?php echo $val['COMMENT5'] ; ?>"><img src="annonces/img/<?php echo $val['PHOTO5'] ; ?>" width="80" height="80" alt="<?php echo $val['COMMENT5'] ; ?>" /></a></td> <?php } } ?> </tr> </table> </p><br /> </div> <div class="bottom"></div> </div> <!-- END : content --> Si vous trouvez la soluce j'offre une héhé PS : On est d'accord le code est chiant pas très optimisé mais concentrons nous sur cette histoire de variable
×
×
  • Créer...