There is a field in which data is stored as `somevalue` set ('value1', 'value2', 'value3'). Tell me how to make an analog query

$data=mysql_fetch_assoc(mysql_query("SELECT * FROM table")); $values=array('value1'=>'Значение1','value2'=>'Значение2','value3'=>'значение3'); echo $values[$data['somevalue']]; 

so that you can simply output the value as $ data ['somevalue'];

  • one
    nothing is clear ... - thunder
  • well, the database stores the name of the values ​​in English, and Russian values are needed when outputting - SPAHI42
  • Can I have more code? What is the "date"? - Rimon
  • Either I’m a fool or something, but you have to sort of like $ data ['somevalue'] value1, or whatever, do print_r ($ data); and show the result, it's easier - Rimon
  • date is an array with a request - SPAHI42

1 answer 1

Method 1, correct:

 $data=mysql_fetch_assoc(mysql_query("SELECT `rus_table`.`value1`,`rus_table`.`value2`,`rus_table`.`value3`, FROM table left join rus_table on `table`.`id`=`rus_table`.`id`")); //rus_table содержит как раз русские значения. echo $data['somevalue']; 

Method 2, simple:

 $data=mysql_fetch_assoc(mysql_query("SELECT * FROM table")); function my_walk(&$item,$key){ $values=array('value1'=>'Значение1','value2'=>'Значение2','value3'=>'значение3'); $item = $values[$item]; } array_walk($data,'mywalk'); echo $data['somevalue']; 

Method 3, only in the special case of a small number of fields:

 Select if(`somevalue`='value1','Значение1',if(`somevalue`='value2','Значение2',if(`somevalue`='value3','Значение3','Значение4'))) as `somevalue` from `table` 
  • the fact is that it is necessary without a separate table (there are only 4 variations of the field) and on mysql - SPAHI42
  • one
    On Mysql - this is a perversion. But you can like this :) * updated - knes
  • cps, so norms - SPAHI42