variable variables question

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

    variable variables question

    I'm a bit unclear on the variable variables section of the PHP manual.
    Here's what I want to accomplish:

    $01_varA="foo"
    $02_varA="bar"
    $03_varB="boo"
    $04_varB="far"

    "01" through "04" are being gathered via mysql query as "id" in the
    example.


    I want to do this.....

    $sql_query=("SE LECT * from database");

    while ($sql_array=($s ql_query)){
    echo $sql_array["id"] . "_varA";
    echo $sql_array["id"] . "_varB";
    }

    ....so that it will echo the values of $01_varA, $02_varA, $03_varB and
    $04_varB in no particular order.

  • samudasu

    #2
    Re: variable variables question

    print ${$sql_array['id'] . '_varA'};

    Comment

    • d

      #3
      Re: variable variables question

      "Dave" <gweedoh@hotmai l.com> wrote in message
      news:1139531157 .994561.231000@ g14g2000cwa.goo glegroups.com.. .[color=blue]
      > I'm a bit unclear on the variable variables section of the PHP manual.
      > Here's what I want to accomplish:
      >
      > $01_varA="foo"
      > $02_varA="bar"
      > $03_varB="boo"
      > $04_varB="far"
      >
      > "01" through "04" are being gathered via mysql query as "id" in the
      > example.
      >
      >
      > I want to do this.....
      >
      > $sql_query=("SE LECT * from database");
      >
      > while ($sql_array=($s ql_query)){
      > echo $sql_array["id"] . "_varA";
      > echo $sql_array["id"] . "_varB";
      > }
      >
      > ...so that it will echo the values of $01_varA, $02_varA, $03_varB and
      > $04_varB in no particular order.
      >[/color]

      Any reason you're not using arrays? :)


      Comment

      • Dave

        #4
        Re: variable variables question

        >print ${$sql_array['id'] . '_varA'};

        This did the trick! Thanks a ton!

        Comment

        Working...