echo VARIABLES

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maximus

    echo VARIABLES

    Guys,

    I have a mysql query that grabs data from the table ... the data is
    "variable names" something like $home $about $contact

    I need the loop to echo those variables as PHP Code, so that they are
    replaced with the variable value and not the variable name.

    any quick function for that?

  • Erwin Moller

    #2
    Re: echo VARIABLES

    Maximus wrote:
    Guys,
    >
    I have a mysql query that grabs data from the table ... the data is
    "variable names" something like $home $about $contact
    >
    I need the loop to echo those variables as PHP Code, so that they are
    replaced with the variable value and not the variable name.
    >
    any quick function for that?
    Hi,

    $bla = "myvarname" ;
    $myvarname = "I am some var";
    echo $$bla;

    Regards,
    Erwin Moller

    Comment

    • Maximus

      #3
      Re: echo VARIABLES

      That's not the case,

      The case is: I have a database table with rows ID and NAME

      ID=1 NAME=$home
      ID=2 NAME=$about

      I make a mysql_fetch_obj ect that grabs the data and echos it in a
      table. I want it to echo $home where $home is a variable with some
      value.

      I need the user to view the $home value .. not the word "$home" itself.

      Erwin Moller wrote:
      Maximus wrote:
      >
      Guys,

      I have a mysql query that grabs data from the table ... the data is
      "variable names" something like $home $about $contact

      I need the loop to echo those variables as PHP Code, so that they are
      replaced with the variable value and not the variable name.

      any quick function for that?
      >
      Hi,
      >
      $bla = "myvarname" ;
      $myvarname = "I am some var";
      echo $$bla;
      >
      Regards,
      Erwin Moller

      Comment

      • Michael Fesser

        #4
        Re: echo VARIABLES

        ..oO(Maximus)
        >That's not the case,
        >
        >The case is: I have a database table with rows ID and NAME
        >
        >ID=1 NAME=$home
        >ID=2 NAME=$about
        >
        >I make a mysql_fetch_obj ect that grabs the data and echos it in a
        >table. I want it to echo $home where $home is a variable with some
        >value.
        >
        >I need the user to view the $home value .. not the word "$home" itself.
        That's exactly what the posted example does. Have a look at variable
        variables.



        Micha

        Comment

        • Erwin Moller

          #5
          Re: echo VARIABLES

          Maximus wrote:
          That's not the case,
          >
          The case is: I have a database table with rows ID and NAME
          >
          ID=1 NAME=$home
          ID=2 NAME=$about
          >
          I make a mysql_fetch_obj ect that grabs the data and echos it in a
          table. I want it to echo $home where $home is a variable with some
          value.
          >
          I need the user to view the $home value .. not the word "$home" itself.
          Hi,

          I am not sure I can follow you.
          Did you actually try my code example?
          It doesn't show '$myvarname', but 'I am some var', which is the content of
          the variable $myvarname, which is defined by $bla.

          So what is the difference with your problem?

          In your case you'll end up with a row, like this:
          for(..fetchrows tuff in $row..){
          echo $row["NAME"]." contains:".$$ro w["NAME"];
          // or cleaner IMHO:
          echo $row["NAME"]." contains:".${$r ow["NAME"]};
          }

          Or am I brainfarting and missing your problem?

          Regards,
          Erwin Moller
          >
          Erwin Moller wrote:
          >Maximus wrote:
          >>
          Guys,
          >
          I have a mysql query that grabs data from the table ... the data is
          "variable names" something like $home $about $contact
          >
          I need the loop to echo those variables as PHP Code, so that they are
          replaced with the variable value and not the variable name.
          >
          any quick function for that?
          >>
          >Hi,
          >>
          >$bla = "myvarname" ;
          >$myvarname = "I am some var";
          >echo $$bla;
          >>
          >Regards,
          >Erwin Moller

          Comment

          Working...