Partage
  • Partager sur Facebook
  • Partager sur Twitter

Afficher image dans boucle foreach

Sujet résolu
    16 mai 2021 à 17:12:02

    Bonjour,

    J'essaie de créer un tableau pour lire les valeurs de ma base de donnée, en POO mais je ne parviens pas à afficher l'image.

    Voici ce que ca m'affiche :

    et voici mon code :

    public function afficherTab() {
            // Définition du gabarit
            $gab = new Template("./");
            $gab->set_filenames(array("body" => "tpltableau.html"));
            // Légende
            $gab->assign_vars(array("nom" => $this->nom));
            // Données
            foreach ($this->data as $ligne) { // boucle <tr>
            $gab->assign_block_vars("ligne"array("rien" => ""));
            foreach($ligne as $val// boucle <td>
            $gab->assign_block_vars("ligne.attribut",
            array("valeur" => $val));
            }

    Et ci dessous la vue :

    $qpl = new Plante2($bdd"Liste des plantes""SELECT NomLatin,NomCommun,photoplante FROM plantes");
    $qpl->executer(); 
    $qpl->afficherTab();

    Je vous remercie pour votre réponse ! 

    • Partager sur Facebook
    • Partager sur Twitter
      16 mai 2021 à 17:16:41

      Hello,

      On peut avoir le tpl ou dois se situé normalement l'image

      • Partager sur Facebook
      • Partager sur Twitter
        16 mai 2021 à 17:29:56

        voila le tpl

        function assign_block_vars($blockname, $vararray)
        	{
        		if (strstr($blockname, '.'))
        		{
        			// Nested block.
        			$blocks = explode('.', $blockname);
        			$blockcount = sizeof($blocks) - 1;
        			$str = '$this->_tpldata';
        			for ($i = 0; $i < $blockcount; $i++)
        			{
        				$str .= '[\'' . $blocks[$i] . '.\']';
        				eval('$lastiteration = sizeof(' . $str . ') - 1;');
        				$str .= '[' . $lastiteration . ']';
        			}
        			// Now we add the block that we're actually assigning to.
        			// We're adding a new iteration to this block with the given
        			// variable assignments.
        			$str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';
        
        			// Now we evaluate this assignment we've built up.
        			eval($str);
        		}
        		else
        		{
        			// Top-level block.
        			// Add a new iteration to this block with the variable assignments
        			// we were given.
        			$this->_tpldata[$blockname . '.'][] = $vararray;
        		}
        
        		return true;
        	}
        function assign_vars($vararray)
        	{
        		reset ($vararray);
        		while (list($key, $val) = each($vararray))
        		{
        			$this->_tpldata['.'][0][$key] = $val;
        		}
        
        		return true;
        	}



        Merci de ton aide

        • Partager sur Facebook
        • Partager sur Twitter
          18 mai 2021 à 14:14:44

          Je pense que tu t'y prends mal, en théorie tu devrais par exemple avoir un fichier par exemple page.tpl 

          et dedans un foreach qui afficherais les informations et là tu pourrais du coup mettre ta balise <img> pour afficher tes images

          • Partager sur Facebook
          • Partager sur Twitter

          Afficher image dans boucle foreach

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown