Probleme fonction php

Bonjour,

pour faire conci, si je fait afficher le code ci dessous par l appel de fonction maf(), il n'y a que la variable $ts qui s affiche, tandis que si j'efface ' fonction maf() { ' et que j'execute betement le code, alors la les edux variables s'affichent ... ca me semble absurde je suis perdus !!!

un peut d aide serra la bienvenue

merci d avance

function maf()
{
$tes='<UL><H4>';

while ($row_tehcnique = mysql_fetch_assoc($tehcnique))
{
$tes.='<LI><a href="./technique.php?select='.$row_tehcnique['job_ID'].'">'.$row_tehcnique['Job'].'</a>';
}
$rows = mysql_num_rows($tehcnique);
if($rows > 0)
{
mysql_data_seek($tehcnique, 0);
$row_tehcnique = mysql_fetch_assoc($tehcnique);
}
$tes.='</UL></H4>';
echo $tes;

$td="teeeeeeeest";
$ts='<a href="./technique.php?select='.$td.'">you</a>';
echo $ts;

}
?>
Configuration: Windows XP
Internet Explorer 7.0

4 réponses

  1. Merci mon vieux j'avais mal compris la fin de ta réponse !

    je ne savais pas que Quand tu arrives dans ta fonction, il ignore ce que tu viens de mettre dans $tehcnique.

    merci milles fois !

    bonne journée
    1. Bonjour.

      As-tu regardé le code source que tu obtiens ?
      J'aurais tendance à dire que tu dois trouver quelque chose de ce genre :
      <UL><H4></UL></H4><a href="./technique.php?select=teeeeeeeest">you</a>


      Si c'est bien le cas, c'est que tu ne passes pas dans ta boucle WHILE.

      Première chose à faire (de toute façon, c'est toujours utile de la faire) : mettre des OR DIE après tes fonctions mysql :
      mysql_connect(...) or die ("Erreur de connexion à MySQL ".mysql_error());
      mysql_select_db(...) or die ("Erreur de connexion à la BDD ".mysql_error());
      mysql_query(...) or die("Erreur de requête ".mysq_error());

      Le problème, dans ton cas, c'est certainement que tu n'as pas défini ta variable $tehcnique, que tu utilises dans
      while ($row_tehcnique = mysql_fetch_assoc($tehcnique)) 


      Pour rappel : si tu fais :
      $tehcnique = mysql_query($marequete) or die ("Erreur de requête ".$marequete."<br />".mysql_error());
      maf();

      Quand tu arrives dans ta fonction, il ignore ce que tu viens de mettre dans $tehcnique.

      Solution : définis ta fonction en lui passant un résultat de requête comme paramètre
      function maf($tehcnique ) {
      ...
      }
      

      Et appelle-la en lui passant le paramètre :
      $resultat= mysql_query($marequete) or die ("Erreur de requête ".$marequete."<br />".mysql_error());
      maf($resultat);
      1. Je vais etre plus long mais peut etre plus précis... .

        Ceci:
        <?php
        $tes='<UL><H4>';

        while ($row_tehcnique = mysql_fetch_assoc($tehcnique))
        {
        $tes.='<LI><a href="./technique.php?select='.$row_tehcnique['job_ID'].'">'.$row_tehcnique['­Job'].'</a>';
        }
        $rows = mysql_num_rows($tehcnique);
        if($rows > 0)
        {
        mysql_data_seek($tehcnique, 0);
        $row_tehcnique = mysql_fetch_assoc($tehcnique);
        }
        $tes.='</UL></H4>';
        echo $tes;

        $td="teeeeeeeest";
        $ts='<a href="./technique.php?select='.$td.'">you</a>';
        echo $ts;

        ?>

        m'affiche corretement les deux variables $ts et $tes tout ce passe comme on s'y attend

        par contre,

        function maf()
        {
        $tes='<UL><H4>';

        while ($row_tehcnique = mysql_fetch_assoc($tehcnique))
        {
        $tes.='<LI><a href="./technique.php?select='.$row_tehcnique['job_ID'].'">'.$row_tehcnique['­Job'].'</a>';
        }
        $rows = mysql_num_rows($tehcnique);
        if($rows > 0)
        {
        mysql_data_seek($tehcnique, 0);
        $row_tehcnique = mysql_fetch_assoc($tehcnique);
        }
        $tes.='</UL></H4>';
        echo $tes;

        $td="teeeeeeeest";
        $ts='<a href="./technique.php?select='.$td.'">you</a>';
        echo $ts;

        }

        maf();
        ?>

        ne m'affiche que la variable $ts correctement étrangement !!!
      2. @l0vers0nJe vais donc être plus court, mais plus expéditif :

        Le code source de ta page donne quoi ?
      3. <html><!-- InstanceBegin template="/Templates/k.dwt.php" codeOutsideHTMLIsLocked="false" -->
        <head>
        <!-- InstanceBeginEditable name="doctitle" -->
        <title>Centre KINOS * Techniques</title>
        <!-- InstanceEndEditable --><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <style type="text/css">
        <!--
        body {
        background-color: #e6f0ec;
        margin-top: 20px;
        margin-bottom: 20px;
        }
        -->
        </style>
        <link href="../style-css/texte.css" rel="stylesheet" type="text/css">
        <style type="text/css">
        <!--
        a:link {
        text-decoration: none;
        }
        a:visited {
        text-decoration: none;
        }
        a:hover {
        text-decoration: underline;
        }
        a:active {
        text-decoration: none;
        }
        -->
        </style>
        <!-- InstanceBeginEditable name="head" -->
        <style type="text/css">
        a.tooltip em {
        display:none;
        }
        a.tooltip:hover {
        border: 0;
        position: relative;
        z-index: 500;
        text-decoration:none;
        }
        a.tooltip:hover em {
        font-style: normal;
        display: block;
        position: absolute;
        top: 20px;
        left: -10px;
        padding: 5px;
        color: #000;
        border: 1px solid #bbb;
        background: #ffc;
        width:170px;
        }
        a.tooltip:hover em span {
        position: absolute;
        top: -7px;
        left: 15px;
        height: 7px;
        width: 11px;
        background: transparent url(/images/image-infobulle.bmp);
        margin:0;
        padding: 0;
        border: 0;
        }
        p
        {
        font-size : 1.1em; /* Définition de la taille de la police de nos paragraphes */
        }

        a.info_bulle span
        {
        display : none; /* Rend invisible tout notre bloc span */
        }

        a.info_bulle
        {
        color : #2F368A;

        text-decoration : none;

        padding : 2px 16px 2px 2px; /*Définition des marges intérieures de notre lien */

        /* Définition de l'arrière plan de notre lien */
        background : transparent url('/images/image-infobulle.bmp') no-repeat right center;

        position : relative; /* Indispensable pour le bon positionnement de l'info-bulle */
        }

        a.info_bulle:hover
        {
        border : 0; /* ligne qui corrige le bug d'IE6 et inférieur */
        }

        a.info_bulle:hover span
        {
        display : block; /* Rend visible notre bloc span */
        position : absolute; /* Sort notre bloc de son conteneur afin de le positionner */

        background : #DDEEFF; /* Définition du fond, sinon on a le même que notre lien */
        border : 1px solid #6699FF; /* Définition des bordures */

        padding : 6px; /* Définition des marges intérieures */
        font-size : 12px;

        width : 180px; /* On fixe une largeur par défaut */

        color : #000; /* Réinitialisation de la couleur du texte */

        text-align : justify; /* Justification du texte */

        cursor : default; /* Réinitialisation de notre curseur, sinon par défaut on a le même que notre lien */

        /* Positionnement de notre info-bulle */
        top : 1.8em;
        left : 1px;

        z-index : 1000; /* Positionne au premier plan l'info-bulle en cas de chevauchement */
        }

        </style>
        <script type="text/javascript" src="overlib.js"></script>

        <!-- InstanceEndEditable -->
        </head>
        <body leftmargin="0" marginwidth="0">
        <!-- ImageReady Slices (menukins-2.psd) -->
        <!-- InstanceBeginEditable name="EditRegion1" -->
        <table width="681" height="451" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
        <!--DWLayoutTable-->
        <tr>
        <td colspan="4"> <img src="../images/index_01.gif" width="248" height="80" alt=""></td>
        <td colspan="5" rowspan="2"> <img src="../images/index_02.gif" width="260" height="89" alt=""></td>
        <td colspan="3" rowspan="2"> <img src="../images/index_03.gif" width="172" height="89" alt=""></td>
        <td> <img src="../images/spacer.gif" width="1" height="80" alt=""></td>
        </tr>
        <tr>
        <td colspan="4" rowspan="2"> <img src="../images/index_04.gif" width="248" height="69" alt=""></td>
        <td> <img src="../images/spacer.gif" width="1" height="9" alt=""></td>
        </tr>
        <tr>
        <td colspan="5"> <img src="../images/index_05.gif" width="260" height="60" alt=""></td>
        <td colspan="3"> <img src="../images/index_06.gif" width="172" height="60" alt=""></td>
        <td> <img src="../images/spacer.gif" width="1" height="60" alt=""></td>
        </tr>
        <tr>
        <td colspan="2"> <a href="../acceuil.php"><img src="../images/index_07.gif" alt="" width="118" height="30" border="0"></a></td>
        <td width="57"> <a href="../infos/"><img src="../images/index_08.gif" alt="" width="57" height="30" border="0"></a></td>
        <td colspan="2"> <a href="../equipe.php"><img src="../images/index_09.gif" alt="" width="94" height="30" border="0"></a></td>
        <td width="93"> <a href="../equipe.php"><img src="../images/index_10.gif" alt="" width="93" height="30" border="0"></a></td>
        <td width="69"> <a href="../preeduc/"><img src="../images/index_11.gif" alt="" width="69" height="30" border="0"></a></td>
        <td width="69"> <a href="../preeduc/"><img src="../images/index_12.gif" alt="" width="69" height="30" border="0"></a></td>
        <td colspan="2"> <a href="../preeduc/"><img src="../images/index_13.gif" alt="" width="64" height="30" border="0"></a></td>
        <td colspan="2"> <a href="../historique/"><img src="../images/index_14.gif" alt="" width="116" height="30" border="0"></a></td>
        <td> <img src="../images/spacer.gif" width="1" height="30" alt=""></td>
        </tr>
        <tr>
        <td height="214" background="../images/index_15.gif"><!--DWLayoutEmptyCell-->  </td>
        <td colspan="10" valign="top" bgcolor="#FFFFFF"><blockquote>
        <p align="right"><br>
        <a href="../acceuil.php" class="texte"> Retour à l'acceuil</a></p>
        </blockquote>
        <p align="left" class="texte"><a href="www.google.fr" class="tooltip"><img src="images/tech.gif" width="400" height="35"><em><span></span>texte de l'infobullefdsfdsfqsdqf fdsf fqsd fds fsdqf qsdfkjsdqfklmjqsdfjiosqdfiqsdjfsd</em></a></p>

        <p align="center" class="texte"><img src="images/8.jpg" width="485" height="485" border="0" usemap="#Map">
        <map name="Map" class="tooltip">

        <area shape="rect" coords="375,43,402,82" alt="membre droit" href="www.google.fr" onMouseOver="return overlib('',CAPTION, 'contenu', STICKY, MOUSEOFF);" onMouseOut="return nd();">

        <area shape="rect" coords="329,94,369,119" href="www.google.fr" onMouseOver="return overlib('',CAPTION, 'contenu');" onMouseOut="return nd();">

        <area shape="rect" coords="206,70,235,96" href="#">
        <area shape="rect" coords="36,94,70,125" href="#">
        <area shape="rect" coords="250,195,286,228" href="#">
        <area shape="rect" coords="241,347,303,399" href="#">
        <area shape="rect" coords="211,121,280,191" href="#">
        <area shape="rect" coords="200,432,246,472" href="#">
        <area shape="rect" coords="294,309,332,347" href="#">
        <area shape="rect" coords="334,408,374,445" href="#">

        </map>
        </p>

        <UL><H4></UL></H4><a href="./technique.php?select=teeeeeuuuuuut j ai dis">you</a> <a id="info_bulle" class="info_bulle" href="https://www.developpez.com/">developpez.com
        <span>
        www.developez.com est la communauté en langue française qui concentre le
        plus de développeurs professionnels avec plus de 130 000 visites par jour.
        </span>
        </a>

        <table border="0" cellspacing="0" cellpadding="0" align="center"><tr>
        <td width="80" height="20" class="text12" align="center" bgcolor="#ccddff">
        <a href="javascript:void(0);"
        onmouseover="return overlib('<strong>1.</strong> "une minuted\'intérieur"', AUTOSTATUS);"
        onmouseout="return nd();">example 1</a>
        </td></tr></table>

        <p align="left" class="texte"> </p></td>
        <td background="../images/index_17.gif"><!--DWLayoutEmptyCell-->  </td>
        <td> <img src="../images/spacer.gif" width="1" height="214" alt=""></td>
        </tr>
        <tr>
        <td colspan="12"> <a href="../index.php"><img src="../images/index_18.gif" alt="" width="680" height="57" border="0"></a></td>
        <td> <img src="../images/spacer.gif" width="1" height="57" alt=""></td>
        </tr>
        <tr>
        <td> <img src="../images/spacer.gif" width="29" height="1" alt=""></td>
        <td width="89"> <img src="../images/spacer.gif" width="89" height="1" alt=""></td>
        <td> <img src="../images/spacer.gif" width="57" height="1" alt=""></td>
        <td width="73"> <img src="../images/spacer.gif" width="73" height="1" alt=""></td>
        <td width="21"> <img src="../images/spacer.gif" width="21" height="1" alt=""></td>
        <td> <img src="../images/spacer.gif" width="93" height="1" alt=""></td>
        <td> <img src="../images/spacer.gif" width="69" height="1" alt=""></td>
        <td> <img src="../images/spacer.gif" width="69" height="1" alt=""></td>
        <td width="8"> <img src="../images/spacer.gif" width="8" height="1" alt=""></td>
        <td width="56"> <img src="../images/spacer.gif" width="56" height="1" alt=""></td>
        <td width="92"> <img src="../images/spacer.gif" width="92" height="1" alt=""></td>
        <td> <img src="../images/spacer.gif" width="24" height="1" alt=""></td>
        <td></td>
        </tr>
        </table>
        <!-- InstanceEndEditable -->
        <!-- End ImageReady Slices -->
        </body>
        <!-- InstanceEnd --></html>
    2. Salut,
      Je comprends pas bien $tes. (le point c'est volontaire ?)
      $tes.='</UL></H4>'
      tu concatène $tes avec ='</UL></H4>'
      c'est ce que tu veux faire ? ou t'es tu trompé dans le nom de la variable ?
      1. oui, le . est pour faire la concaténation des chaines, comme je compte générer le milieu de la chaine avec un wihle il m'a semblé que faire un .= étais la meilleure solution .

        comme je commance $tes='<UL><H4>';
        ensuite je génere le milieu,
        je termine par: $tes.='</UL></H4>';

        je pense que le probleme n'est pas la, car quand je fait afficher le bout de code au travers de l appel de la fonction ca ne marche pas, mais quand je fait simplement executer le code ligne apres ligne, le contenu s affiche bien comme il le faut ... vraiement étrange