sorry for my english!
I need use this column(feature) for show features, filters for products and in some language(It depends on the country).
I have products table(innodb) and a column(json) features, the column feature is like this: {feature:{ [{"en": "System Operation", "it": "Sistema operativo", "value": "IOS 8" }, { "en": "Memory Ram", "it": "Memoria Ram", "value": "16 Gb" }, { "en": "display", "it": "schermo", "value": "5.5\"" }]} Here have just 2 language but can have 30 or 100 language.
For show feature i use foraech in php I should optimize... maybe in mysql if is possible. $language_detect = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if($language_detect == "it") {$lang_det = "it";} elseif($language_detect == "en") {$lang_det = "en";} elseif.. elseif... foreach($feature->feature as $row) { foreach($row as $key => $val){ if($key == '$lang_det'){ echo $key->$lang_det .' ' . $val . ' : ' ; } if($key == 'value'){ echo $val . '
' ; } } } The really first problem is: how I can make the query like this result?: [{ "en": "System Operation", "value": "IOS 8" }, { "en": "Memory Ram", "value": "16 Gb" }, { "en": "display", "value": "5.5\"" }] and second problem is: how can I search product/s with the feature/s selected? In mysql sure :) Thank you!!
I need use this column(feature) for show features, filters for products and in some language(It depends on the country).
I have products table(innodb) and a column(json) features, the column feature is like this: {feature:{ [{"en": "System Operation", "it": "Sistema operativo", "value": "IOS 8" }, { "en": "Memory Ram", "it": "Memoria Ram", "value": "16 Gb" }, { "en": "display", "it": "schermo", "value": "5.5\"" }]} Here have just 2 language but can have 30 or 100 language.
For show feature i use foraech in php I should optimize... maybe in mysql if is possible. $language_detect = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if($language_detect == "it") {$lang_det = "it";} elseif($language_detect == "en") {$lang_det = "en";} elseif.. elseif... foreach($feature->feature as $row) { foreach($row as $key => $val){ if($key == '$lang_det'){ echo $key->$lang_det .' ' . $val . ' : ' ; } if($key == 'value'){ echo $val . '
' ; } } } The really first problem is: how I can make the query like this result?: [{ "en": "System Operation", "value": "IOS 8" }, { "en": "Memory Ram", "value": "16 Gb" }, { "en": "display", "value": "5.5\"" }] and second problem is: how can I search product/s with the feature/s selected? In mysql sure :) Thank you!!
Asked by user112752
(3 rep)
Apr 16, 2016, 04:09 PM
Last activity: Jun 23, 2017, 09:53 PM
Last activity: Jun 23, 2017, 09:53 PM