variable inside a $row statement
Posted: Tue Jan 13, 2009 3:08 am
hi,
i am really struggling to find a way around this one but i am sure it's something simple for those who know.
i am working on a page where my user will input two languanges from a form: a mother language and a target language. these are stored under $mothlang and $targlang. i have a db table with words stored in many languages, with field names english, spanish, german etc. etc.
to get an english word from a row i would just use this code:
echo $row['english'];
to get the spanish:
echo $row['spanlish']; etc.
but what i want is to use the variable to control what is retrieved from the table. so something like this code:
echo $row['$mothlang'];
this code doesn't work however. obviously there is a correct way to do this but i can't find the answer anywhere. any help greatly appreciated.
i am really struggling to find a way around this one but i am sure it's something simple for those who know.
i am working on a page where my user will input two languanges from a form: a mother language and a target language. these are stored under $mothlang and $targlang. i have a db table with words stored in many languages, with field names english, spanish, german etc. etc.
to get an english word from a row i would just use this code:
echo $row['english'];
to get the spanish:
echo $row['spanlish']; etc.
but what i want is to use the variable to control what is retrieved from the table. so something like this code:
echo $row['$mothlang'];
this code doesn't work however. obviously there is a correct way to do this but i can't find the answer anywhere. any help greatly appreciated.