Liste deroulante avec PEAR

Résolu
Bonjour,
j'aimerai savvoir comment faire pour creer une liste deroulante en utilisant pear

en php j'ai :

echo "<select name='ref' size=1>";


while ($lig2=mysql_fetch_row($res2))

	{

		echo'<option value='.$lig2[0].'>'.$lig2[0].'</option>';

	}
echo "</select>";

?>


c'ets pareil en pear??

MERCI D'AVANCE
Configuration: Linux
Firefox 2.0.0.11

7 réponses

  • Votes
  • Date
  • Date décroissante
Résumé de la discussion

La problématique centrale est de générer une liste déroulante en PHP en utilisant PEAR, et de savoir si la même approche que le code HTML/PHP standard s'applique. Pour PEAR, la liste déroulante se construit comme en PHP classique, mais il faut s'assurer que les extensions et la librairie DB sont correctement chargées et que la requête renvoie des résultats. Des erreurs fréquentes comme 'Call to undefined function: fetchRow' ou des résultats nuls sont discutées, avec des conseils sur le chargement correct de DB.php, l’utilisation de fetchRow et DB_FETCHMODE_ASSOC. Enfin, des échanges notent que l'affichage peut rester vide si la requête ne retourne aucun résultat, et que certains proposent des alternatives pour éviter l'affichage en l'absence de données.

Bobot (l’IA à votre service)
  1. Salut!
    Te revoila ^^
    Comme je te l'ai deja dit PEAR est un framework, et ça ne va pas changer la façon de faire une liste déroulante. Donc ta liste déroulante est très bien comme elle est.
    Par contre je me demandais l'interet de mettre tes select en echo?!?

    echo "<select name='ref' size=1>";
    echo "</select>";
    1. coucou :)
      t'es attiré par mes soucis de codage dis donc :p

      je sais pas pour les select, comme ça ou autrement c'est casi pareil ^^
      l'interet c'est pour si ya pas de resultat rien afficher mais bon je le fais pas ça :p

      donc je laisse ma liste comme ça :)

      jai un soucis, un message d'erreur ; ça viendrait de la connexion mais je sais pas quoi faire pour arranger ça

      Fatal error: Call to undefined function: assertextension() in /usr/share/pear/DB/mssql.php on line 79
  2. Bah t'appelles une fonction qu'il ne trouve pas.
    Et en effet, elle n'est pas dans /usr/share/pear/DB/mssql.php
    1. quel fonction?
      mon code c'est :
      <?php
      
      error_reporting(E_ALL);
      
      include ("connexion.php");
      
      ?>


      et connexion.php c'est :

      <?php
      
      require_once('DB.php');
      $dbType="mysql";
      $host="*******";
      $account="***";
      $pass="***";
      $dbName="cartouche";
      $dsn=$dbType."://".$account.":".$pass."@".$host."/".$dbName;
      
      
      $db = DB::connect($dsn);
      
      if (DB::isError($db)){
      echo"ERREUR :".$db->getMessage();
      }
      ?>
  3. Regarde dans DB.php si il y a la fonction assertextension() !
    1. jai fait dans lediteur de texte rechercher >assertextension()
      il ne trouve rien
  4. Le voila le probleme!!
    Dans mon db.php je l'ai cette fonction, et visiblement il te la manque...
    Je te la passe t'as qu'a l'insérer...

    function assertExtension($name)
    {
    if (!extension_loaded($name)) {
    $dlext = OS_WINDOWS ? '.dll' : '.so';
    $dlprefix = OS_WINDOWS ? 'php_' : '';
    @dl($dlprefix . $name . $dlext);
    return extension_loaded($name);
    }
    return true;
    }

    Il faut que tu l'inseres dans la classe DB
    1. moi dans class DB j'ai :

      class DB
      {
              function &factory($type, $options = false)
          {
              if (!is_array($options)) {
                  $options = array('persistent' => $options);
              }
      
              if (isset($options['debug']) && $options['debug'] >= 2) {
                  // expose php errors with sufficient debug level
                  include_once "DB/{$type}.php";
              } else {
                  @include_once "DB/{$type}.php";
              }
      
              $classname = "DB_${type}";
      
              if (!class_exists($classname)) {
                  $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
                                          "Unable to include the DB/{$type}.php"
                                          . " file for '$dsn'",
                                          'DB_Error', true);
                  return $tmp;
              }
      
              @$obj = new $classname;
      
              foreach ($options as $option => $value) {
                  $test = $obj->setOption($option, $value);
                  if (DB::isError($test)) {
                      return $test;
                  }
              }
      
              return $obj;
          }


      je le rajoute après ton truc?
    2. @LiLou LiLaje lai mis après et il me repond maintenant
      ERREUR :DB Error: connect failed


      qui est le message d'erreur après la connexion :

      if (DB::isError($db))
      {
      	echo"ERREUR :".$db->getMessage();
      }
      ?>
  5. Je t'aurai bien copié la mienne, mais elle fait plus de 500 lignes...
    Bah oui rajoute le apres!
    1. wooh merci c'est bon ca marche :)

      le serveur etait en plus pas connecté :p hi hi

      et là ça va :)
      merci beaucoup !!!

      mais jai pleins de fautes sur mon code
    2. @LiLou LiLaPour une fois que j'arrive à t'aider!!! ^^
      Mets les erreurs ici pour voir si je suis dans un bon jour.
    3. @Jeren
      while($result=$rsc->fetchRow(DB_FETCHMODE_ASSOC))
      	{
      		echo"<tr><td>".$result[0]."</td><td>".$result[1]."</td><td>".$result[2]."</td></tr>";
      	}
      ?> 


      l'erreur est sur la ligne du echo blabla
    4. @Jeren
      while($result=$rsc->fetchRow(DB_FETCHMODE_ASSOC))
      {
      echo "<tr><td>$result[0]</td><td>$result[1]</td></tr>";
      }


      l'erreur :


      Fatal error: Call to undefined function: fetchrow() in /var/www/Portail_Logistique/cartouchesite/choixref.php on line 31
  6. L'erreur n'est pas sur la ligne echo mais sur la ligne du dessus, tu appelles la fonction fetchrow() qui est inconnu!
    1. tu veux vraiment le savoir :o .... c'est parti :

      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 0 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 1 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      Notice: Undefined offset: 2 in /var/www/Portail_Logistique/cartouchesite/liste.php on line 46
      


      tout ca :) (ligne 46 = echo blabla)

      c'est un peu repititif mais c'est mes messages d'erreurs
    2. ce'st pour une autre page celui là :p
    3. Contributeur
      @LiLou LiLaRe,

      Tes erreurs sont normales, tu as cette ligne de code :
      while($result=$rsc->fetchRow(DB_FETCHMODE_ASSOC)){
      }
      


      Or, que peux tu remarquer dans ton test ? Tu fais une AFFECTATION et non un test, ce qui est donc toujours TRUE, donc ta boucle est toujours vérifiée !
      Or, comme dis plus haut, la fonction fetchRow n'existe pas, conclusion la valeur 'null' est attribuée à ta variable $result, du coup lorsque tu tente d'accèder à ce qu'il y a dedans (cf $result[0], [1], [2]), tu as l'erreur comme quoi l'offset 0, 1, 2 sont inconnus (puisque ta variable est nulle)

      Conclusion, ajoute un test dans ta boucle comme ceci :
      while( ($result=$rsc->fetchRow(DB_FETCHMODE_ASSOC)) != null ){
      }
      


      Et puis bien sur il faut modifier la fonction appelée si elle n'existe pas (fetchRow)
    4. @kij_82trop fort mes erreurs sont partis

      par contre le tableau qui s'affiche est totalement vide pourquoi?
    5. comment ca se fait que fetchrow soit inconnu ??
      il marche sur l'autre fichier ( ou y avait le probleme !=null)
      pourtant c 'est ecrit pareil
  7. oui yavait ça et autre chose
    c'est bon ça marche :)

    <?//liste deroulante pour selection par reference
    
    $rsc2=$db->query("SELECT Distinct IdReference FROM sorties;");
    
    if(DB::isError($rsc2))
    die($rsc2->getMessage());
    
    echo "Selection par reference de cartouche";
    echo "<form action=\"choixref.php\" method=\"post\">";
    echo "<select name=\"ref\" size=1>";
    
    while ($row2=$rsc2->fetchRow())
    	{
    	echo"<option value='".$row2[0]."'>".$row2[0]."</option>";
    
    	}
    echo "</select>";
    echo "<input type=\"submit\" name=\"valideref\" value=\"Rechercher\">";
    
    echo "</form>";
    ?>


    il ne prenait pas ma requete jai un soucis avec la table , aucune requete ne marche dessus
    mais pour ça c'est bon ;)

    merci beaucoup