value of one column as key for another
Posted: Sun Apr 03, 2011 10:02 am
I have a table 'languages' with columns field, english, french, german.
I have variable $language = 'french'
I want the value of 'field' to become the key for the value of 'french'
For example, if field = city and french = ville, I want to end up with $city having the value ville.
I have tried many ways, including the following, but nothing works. Please put me out of my misery!
I have variable $language = 'french'
I want the value of 'field' to become the key for the value of 'french'
For example, if field = city and french = ville, I want to end up with $city having the value ville.
I have tried many ways, including the following, but nothing works. Please put me out of my misery!
Code: Select all
$sql=mysql_query("SELECT field, $language FROM languages");
while($set=mysql_fetch_assoc($sql)){
foreach ($set as $value){
$now = array($set['field'] => $set[$language]);
}
extract($now);
echo $city;