products(prod_id, prod_name,...)
attribute_key(attr_key_id, attr_name)
attributes_values(attr_val_id, attr_key_id, value)
product_attr_values(id,product_id,attr_val_id)
MYSQLの結果を配列定義として定義しました。問題は私が に同じ商品の異なる値を同じ属性に連結して、 のカンマ(;)で接続することです。しかし、私はそれを連結せずに結果を得ることができます。ヘルプは高く評価しました。mysqlの結果をPHPでピボットテーブルに変換
$shop = Array
(
"0" => Array
(
"id" => 9,
"prodname" => 'Ramkinkar Baij',
"attribute_name" => 'Author',
"value" => 'sabsyasachi das'
),
"1" => Array
(
"id" => 10,
"prodname" => 'Ramkinkar Baij',
"attribute_name" => 'Author',
"value" => 'Ela Datta'
),
"2" => Array
(
"id" => 11,
"prodname" => 'Ramkinkar Baij',
"attribute_name" => 'Editor',
"value" => 'Sathi Basu'
),
"3" => Array
(
"id" => 12,
"prodname" => 'Ramkinkar Baij',
"attribute_name" => 'Editor',
"value" => 'Radha Prasad Gupta'
),
"4" => Array
(
"id" => 13,
"prodname" => 'Ramkinkar Baij',
"attribute_name" => 'Place_of_Publication',
"value" => 'Panagarh, Burdwan, West Bengal'
),
"5" => Array
(
"id" => 14,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Author',
"value" => 'sabsyasachi das'
),
"6" => Array
(
"id" => 15,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Author',
"value" => 'Ela Datta'
),
"7" => Array
(
"id" => 16,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Translated_by',
"value" => 'partha dasgupta'
),
"8" => Array
(
"id" => 17,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Editor',
"value" => 'Bandana Mukhopadhay'
),
"9" => Array
(
"id" => 18,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Editor',
"value" => 'Sathi Basu'
),
"10" => Array
(
"id" => 19,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Translated_Title',
"value" => '(Second World Telugu Conference, 1981)'
),
"11" => Array
(
"id" => 20,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Place_of_Publication',
"value" => 'Hyderabad'
),
"12" => Array
(
"id" => 21,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Foreword',
"value" => 'Information on Government organisations of Art and Culture in Andhra Pradesh'
),
"13" => Array
(
"id" => 22,
"prodname" => 'Rendava Prapancha Telugu Mahasabhalu, 1981',
"attribute_name" => 'Descriptive_Tags',
"value" => 'Conference, Language'
)
);
$groups = array();
foreach($shop as $key => $array){
//$type is not necessary, it's just for clarity below
$product = $array['prodname'];
if(!isset($groups[$product])){
$groups[$product] = array();
$groups[$product]['prod'] = $array['prodname'];
}
$groups[$product][$array["attribute_name"]] = $array['value'];
}
//then combine the groups into a master array
$out = array();
foreach($groups as $g){
$out[] = $g;
}
echo '<pre>'. print_r($out, true).'</pre>';
print "<pre>";
//print_r($groups);
print "</pre>";
セミコロンです。しかし、なぜあなたは何かを連結しなければならないのですか? – Strawberry
ステートメントBは、ステートメントAの必要な結果ではありません。 – Strawberry
同様に。参照:[私は非常に単純なSQLクエリと思われるものに対してMCVEを提供するのはなぜですか?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-私にとっては非常にシンプルなSQLクエリです) – Strawberry