Web Analytics Made Easy -
StatCounter dynamic variable name - CodingForum

Announcement

Collapse
No announcement yet.

dynamic variable name

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

  • dynamic variable name

    Hello all, I have looked into this and am still confused...hopefully someone can help. Thank you in advance...

    This is the situation:
    I have a MySQL query that returns a result array yielding $enrow[0], $enrow[1], etc. and a result array yielding $sprow[0], $sprow[1], etc.

    I want to call one of the results based on a user inputted variable (ie $lan="en" or $lan="sp") giving
    PHP Code:
    echo ' hello' $enrow[0] . 'how are you?'
    I tried
    PHP Code:
    echo 'hello' . ${$lan."row[0]"} . 'how are you'
    doesn't work.
    Last edited by madshadow; Oct 3, 2006, 10:20 PM.

  • #2
    could you psot some more code, because i don't realy understand the
    I have a MySQL query that returns a result array yielding $enrow[0], $enrow[1], etc. and a result array yielding $sprow[0], $sprow[1], etc.
    and i think the best sollution will be to only create one result-array. (so to not use the variable variablenames on the echo, but on a dynamically created sql-statement.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      try:
      PHP Code:
      echo 'hello '.${$lan.'row'}[0].' how are you?'
      but I'd agree with raf, in that having just one $row, with the appropriate language information, is nicer.
      My thoughts on some things: http://codemeetsmusic.com
      And my scrapbook of cool things: http://gjones.tumblr.com

      Comment


      • #4
        Thanks guys.... The naming method worked fine but you guys are right....I should just do a dynamic sql statement.

        Much appreciated!

        Comment

        Working...
        X