Page 1 of 1

variable inside a $row statement

Posted: Tue Jan 13, 2009 3:08 am
by russ72g
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.

Re: variable inside a $row statement

Posted: Tue Jan 13, 2009 3:16 am
by VladSun

Code: Select all

echo $row[$mothlang];
Try

Code: Select all

$s = "String";
echo 'This is a $s';
echo "This is a $s";
echo "This is a ".$s;
echo 'This is a '.$s;
to see the differences in using single/double quotes and string concatenation.

Re: variable inside a $row statement

Posted: Tue Jan 13, 2009 3:21 am
by russ72g
I knew it would be something simple. Many thanks for you your time. That has solved the problem and I have learned something. :)