Problème d'affichage php/javascript
Amelie0528
Messages postés
51
Date d'inscription
Statut
Membre
Dernière intervention
-
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
je viens vers vous parce que j'ai perdu beaucoup de temps sans trop avancé
je souhaite faire un tri sur un tableau
le tableau est affiché grâce a un SELECT sur la BDD
mtn je veut faire un tri sur les résultat affiché, quand je clic sur une colonne il faut que ça fait le tri .
mon problème est que le javascript détecte lorsque je clic sur une colonne mais la page tourne sans rien affiché
voila mon code
merci d'avance
je viens vers vous parce que j'ai perdu beaucoup de temps sans trop avancé
je souhaite faire un tri sur un tableau
le tableau est affiché grâce a un SELECT sur la BDD
mtn je veut faire un tri sur les résultat affiché, quand je clic sur une colonne il faut que ça fait le tri .
mon problème est que le javascript détecte lorsque je clic sur une colonne mais la page tourne sans rien affiché
voila mon code
merci d'avance
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Recherche</title> <style> body{background-color: #1dcfd1; margin: 20px;} table { border-width:1px; border-style:solid; border-color:black; width:90%; border-collapse: collapse; } a{margin-left:80%;} td { border-width:1px; border-style:solid; border-color:black; width:10%; text-align: center; } th { border-width:1px; border-style:solid; border-color:black; width:5%; text-align: rand; } </style> </head> <body> <a href="consommation.php">Détails de consommation</a> <div class="gauche"> <!-- recherche par nom --> <form action ="cherche.php" method="post"> <span>Recherche par nom :</span> <input type="text" id="search" name="search"/> <input type="submit" value="Appliquer"> <input type="reset" value="Reset"> </form> <!-- recherche par Numero --> <form action ="cherche.php" method="post"> <span>recherche numero client :</span> <input type="text" id="numero" name="numero"/> <input type="submit" value="Appliquer"> <input type="reset" value="Reet"> </form> <!-- obtenir toute les informations d'un client --> <?php // connexion bdd try { $bdd = mysqli_connect('localhost', 'root', '06193475L', 'base-pacetel'); $bdd->set_charset("utf8"); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } if(isset($_POST['liste1'])){ //si la liste a été "postée" c ad choix fait $liste1=$_POST['liste1']; }else{ $liste1=-1; } ?> Sélectionnez un client : <form name="form1" method="post" action="index.php"> <select name="liste1" onchange=" form1.submit();"> <option value=-1>-- Choisissez -- </option> <option>Lumelec</option><!-- il faut cette ligne pour avoir obliagtoirement un changement --> <option>client20</option> <?php //traitement du filtre if(isset($_GET['orderby'])) { $req = "SELECT DISTINCT nomclient,Numero,Destination,value,valeur,coutCDR,Type,mois FROM `facture2015` WHERE `nomclient` ='".$escaped_liste1."' ORDER BY ".$_GET[' orderby']; } else { $req = "SELECT DISTINCT nomclient,Numero,Destination,value,valeur,coutCDR,Type,mois FROM `facture2015` WHERE `nomclient` ='".$escaped_liste1."'"; } $res1 = mysqli_query($bdd,$req); //affichage du tableau apres filtre echo "<table>"; while ($data1 = mysqli_fetch_array($res1)) { echo "<tr><td>".$data1['nomclient']."</td><td>".$data1['Numero']."</td><td>".$data1['Destination']."</td><td>".$data1['value']."</td><td>".$data['valeur']."</td><td>".$data1['coutCDR']."</td><td>".$data1['Type']."</td><td>".$data1['mois']."</td></tr>"; } echo "</table>"; //or die('erreur affichage'); // selection $requete = "SELECT nomclient FROM facture2015"; $execution_requete = mysql_query($requete); while($total = mysql_fetch_array($execution_requete)) //Liste déroulante client { echo "<option value=\"".$total["nomclient"]."\""; if($liste1==$total['nomclient']) { echo "selected"; }//ça c'est pour garder la selection lors du réaffichage echo ">".$total['nomclient']."</option>\n"; } ?> </select> </form> <?php if($liste1 != -1){ //si on a fait un choix //on refait une requette avec une condition $escaped_liste1 = mysql_real_escape_string($liste1); $req = "SELECT DISTINCT nomclient,Numero,Destination,value,valeur,coutCDR,Type,mois FROM `facture2015` WHERE `nomclient` ='".$escaped_liste1."' ORDER BY coutCDR DESC LIMIT 0, 100 "; $res = mysqli_query($bdd,$req); // on va scanner tous les tuples un par un echo "<table>"; echo "<th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=entreprise'\">entreprise</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Numero'\">Numero</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Destination'\">Destination</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=value'\">value</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=valeur'\">valeur</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=coutCDR'\">coutCDR</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Type'\">Type</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=mois'\">mois</a></th>" ; while ($data = mysqli_fetch_array($res)) { // on affiche les résultats echo "<tr><td>".$data['nomclient']."</td><td>".$data['Numero']."</td><td>".$data['Destination']."</td><td>".$data['value']."</td><td>".$data['valeur']."</td><td>".$data['coutCDR']."</td><td>".$data['Type']."</td><td>".$data['mois']."</td></tr>"; } echo "</table>"; //or die('erreur affichage'); } ?> </form> </div> <script> // execute la fonction quand je clic function myFunction() { document.getElementById("orderby").click(); // Clic } </script> </body> <html>
EDIT : Ajout du LANGAGE dans les balises de code (la coloration syntaxique).
Explications disponibles ici : ICI Merci d'y penser dans tes prochains messages. |
A voir également:
- Problème d'affichage php/javascript
- Affichage double ecran - Guide
- Easy php - Télécharger - Divers Web & Internet
- Problème affichage fenêtre windows 10 - Guide
- Windows 11 affichage classique - Guide
- Problème affichage page internet google chrome - Forum Téléphones & tablettes Android
2 réponses
Salut,
Tu as un espace en trop au niveau de la récupération du paramètre get orderby dans la construction de ta requête :
Bonne journée
Tu as un espace en trop au niveau de la récupération du paramètre get orderby dans la construction de ta requête :
$_GET[' orderby']
Bonne journée
Bonjour,
Je me suis permis de refaire un peu mieux ton code :
Cordialement,
Jordane
Je me suis permis de refaire un peu mieux ton code :
<?php //Fichier de connexion à la BDD : cnxBDD.php // A include lorsque tu en as besoin. // connexion bdd try{ $bdd = mysqli_connect('localhost', 'root', '06193475L', 'base-pacetel'); $bdd->set_charset("utf8"); }catch (Exception $e){ die('Erreur : ' . $e->getMessage()); } ?>
<?php //On place le code PHP avant le HTML //Ca rend ton code plus simple à debuguer en cas de pb // Pour afficher les éventuelles erreurs PHP error_reporting(E_ALL); //Connexion à la BDD require_once "cnxBDD.php"; //Récupération "propre" des variables $orderby = !empty($_GET['orderby']) ? " ORDER BY " . $_GET['orderby'] : ''; $liste1= isset($_POST['liste1']) ? $_POST['liste1'] : -1; $escaped_liste1 = mysql_real_escape_string($liste1); //traitement du filtre $req = "SELECT DISTINCT nomclient ,Numero ,Destination ,value ,valeur ,coutCDR ,Type ,mois FROM `facture2015` WHERE `nomclient` ='".$escaped_liste1."' ".$orderby; $res1 = mysqli_query($bdd,$req) or die("Erreur !"); $req = "SELECT DISTINCT nomclient ,Numero ,Destination ,value ,valeur ,coutCDR ,Type ,mois FROM `facture2015` WHERE `nomclient` ='".$escaped_liste1."' ORDER BY coutCDR DESC LIMIT 0, 100 "; $res = mysqli_query($bdd,$req); // selection $requete = "SELECT nomclient FROM facture2015"; $execution_requete = mysql_query($requete) or die("Erreur !"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Recherche</title> <style> body{background-color: #1dcfd1; margin: 20px;} table { border-width:1px; border-style:solid; border-color:black; width:90%; border-collapse: collapse; } a{margin-left:80%;} td { border-width:1px; border-style:solid; border-color:black; width:10%; text-align: center; } th { border-width:1px; border-style:solid; border-color:black; width:5%; text-align: rand; } </style> </head> <body> <a href="consommation.php">Détails de consommation</a> <div class="gauche"> <!-- recherche par nom --> <form action ="cherche.php" method="post"> <span>Recherche par nom :</span> <input type="text" id="search" name="search"/> <input type="submit" value="Appliquer"> <input type="reset" value="Reset"> </form> <!-- recherche par Numero --> <form action ="cherche.php" method="post"> <span>recherche numero client :</span> <input type="text" id="numero" name="numero"/> <input type="submit" value="Appliquer"> <input type="reset" value="Reet"> </form> <!-- obtenir toute les informations d'un client --> Sélectionnez un client : <form name="form1" method="post" action="index.php"> <select name="liste1" onchange=" form1.submit();"> <option value=-1>-- Choisissez -- </option> <option>Lumelec</option><!-- il faut cette ligne pour avoir obliagtoirement un changement --> <option>client20</option> <?php while($total = mysql_fetch_array($execution_requete)) { //Liste déroulante client $selected = $liste1==$total['nomclient'] ? " selected = 'selected' " : ''; echo "<option value='".$total["nomclient"]."' $selected >".$total['nomclient']."</option>\n"; } ?> </select> </form> <?php //affichage du tableau apres filtre echo "<table>"; while ($data1 = mysqli_fetch_array($res1)) { echo "<tr> <td>".$data1['nomclient']."</td> <td>".$data1['Numero']."</td> <td>".$data1['Destination']."</td> <td>".$data1['value']."</td> <td>".$data['valeur']."</td> <td>".$data1['coutCDR']."</td> <td>".$data1['Type']."</td> <td>".$data1['mois']."</td> </tr>"; } echo "</table>"; if($liste1 != -1){ //si on a fait un choix // on va scanner tous les tuples un par un echo "<table>"; echo "<th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=entreprise'\">entreprise</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Numero'\">Numero</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Destination'\">Destination</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=value'\">value</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=valeur'\">valeur</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=coutCDR'\">coutCDR</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=Type'\">Type</a></th> <th><a id=\"orderby\" onclick=\"window.location.href = window.location.href + '?orderby=mois'\">mois</a></th>" ; while ($data = mysqli_fetch_array($res)) {// on affiche les résultats echo "<tr> <td>".$data['nomclient']."</td> <td>".$data['Numero']."</td> <td>".$data['Destination']."</td> <td>".$data['value']."</td> <td>".$data['valeur']."</td> <td>".$data['coutCDR']."</td> <td>".$data['Type']."</td> <td>".$data['mois']."</td> </tr>"; } echo "</table>"; //or die('erreur affichage'); } ?> </div> <script type="text/javascript"> // execute la fonction quand je clic function myFunction() { document.getElementById("orderby").click(); // Clic } </script> </body> <html>
Cordialement,
Jordane
merci jordance c'est super propre votre code, merci beaucoup
par contre il retourne un message d'erreur qui un rapport avec ce qui expliquait Pitet, le pdo , mysqli
par contre il retourne un message d'erreur qui un rapport avec ce qui expliquait Pitet, le pdo , mysqli
Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\recherche\index.php on line 17
oui effectivement j'ai enlevé l'espace mais ca change rien
Vérifie également si tu as des erreurs PHP (dans le fichier error.log de ton serveur web par exemple).
Dans l'idéal il faudrait également gérer les éventuelles erreurs sql, mais les deux points ci-dessus devrait nous permettre de trouver la cause du problème.
PS: je n'ai pas regardé ton code en détail mais tu utilises à la fois l'API Mysql (les fonctions mysql_*) et l'API Mysqli (les fonctions mysqli_*) ce qui n'est pas recommandé.
Préfère utiliser uniquement l'API Mysqli (où passer à PDO) mais l'API Mysql ne devrait plus être utilisée.
oui dans le fichier log j'ai ca comme erreur:
En effet le paramètre passé est le retour de la fonction mysql_query, et cette dernière retourne FALSE dans le cas où la requête sql ne s'est pas exécuté correctement. Tu as donc une erreur dans la construction de ta requête sql.
Il faut donc gérer et afficher les messages des éventuelles erreurs sql avec la mysql_error (pour l'API Mysql) ou mysqli_error (pour l'API Mysqli) , par exemple :
Concernant les API de bdd, le passage vers PDO n'est pas obligatoire mais l'utilisation/le remplacement de l'API Mysql par l'API Mysqli est plus que recommandé :
https://www.php.net/manual/fr/mysqlinfo.api.choosing.php