Announcement

Collapse
No announcement yet.

variable variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • variable variable

    i need to have some of my variable variable

    i have a code with 10 execution the only change are the suffix of the variable

    i.e :

    PHP Code:
     $req_resultat=mysql_query("select * from img, user_reponse where user_reponse.id='2325' and img.id='1' ") or die (mysql_error());
    while (
    $show_resultat=mysql_fetch_object($req_resultat))
    {
    // Notation Réponse 
    $reponse1 $show_resultat->r1;
    echo(
    " Réponse du Quizz : $reponse1<br>");
    $rep_membre1 $show_resultat->reponse1;
    echo(
    " Réponse du Membre : $rep_membre1<br>");
    $reponse1 ucfirst($reponse1);
    $reponse1 str_replace("(","",$reponse1);
    $reponse1 addslashes($reponse1);

    this part :
    $reponse1 = $show_resultat->r1;
    echo(" Réponse du Quizz : $reponse1<br>");
    $rep_membre1 = $show_resultat->reponse1;
    echo(" Réponse du Membre : $rep_membre1<br>");
    $reponse1 = ucfirst($reponse1);
    $reponse1 = str_replace("(","",$reponse1);
    $reponse1 = addslashes($reponse1)will be 10 times in my page with $reponse2 $show_resultat->r2 .... $reponse3 ..... i need something like this :
    PHP Code:
    $req_resultat=mysql_query("select * from img, user_reponse where user_reponse.id='2325' and img.id='1' ") or die (mysql_error());
    while (
    $show_resultat=mysql_fetch_object($req_resultat))
    {
    // Notation Réponse 
    for($u=1;$u<11;$u++)
    {
    $reponse$u $show_resultat->r$u;
    echo(
    " Réponse du Quizz : $reponse$u<br>");
    $rep_membre$u $show_resultat->reponse$u;
    echo(
    " Réponse du Membre : $rep_membre$u<br>");
    $reponse$u ucfirst($reponse$u);
    $reponse$u str_replace("(","",$reponse$u);
    $reponse$u addslashes($reponse$u);
    }

    so how i need to write all variable with $u inside ?

  • #2
    Instead of referring to $reponse1 use ${"reponse$u"}.
    Chen Avinadav
    Better to remain silent and be thought a fool than to speak out and remove all doubt.

    גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

    Comment


    • #3
      and for $show_resultat->r1 ?

      Comment


      • #4
        $show_resultat->{"r$u"}.
        Chen Avinadav
        Better to remain silent and be thought a fool than to speak out and remove all doubt.

        גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

        Comment


        • #5
          thanks it works perfectly

          Comment

          Loading...
          Working...
          X