I have a sample table like
I want to get records like
Array(
'col-1' => ['v1','v4','v7'],
'col-2' => ['v2','v5','v8'],
'col-3' => ['v3','v6','v9'],
)
Is there a way to get it in MySQL
I have a sample table like
I want to get records like
Array(
'col-1' => ['v1','v4','v7'],
'col-2' => ['v2','v5','v8'],
'col-3' => ['v3','v6','v9'],
)
Is there a way to get it in MySQL
Please check if this thread helps you.
How to transform vertical data into horizontal data with SQL?
From the way you listed your desired output I am guessing that you are using PHP. Just in case you are interested in a much simpler PHP based solution to your problem, here it is:
$r=mysqli_query($connection,'select * from tbl');
$arr=array(); $res=array();
while ($d=mysqli_fetch_assoc($r)) $arr[]=$d;
foreach ($arr as $d)
foreach ($d as $key => $val) $res[$key][]=$val;
print_r($res);
Hi I think you need to change your DB structure
you can create two tables e.g
// Product Table i wish
id | name
---------
1 | test
2 | Examplace product
then you can create the other table
product_colum_table
id | product_id | product_colum_or_data
1 | 1 | Something
2 | 1 | some other data
3 | 2 | product name
4 | 2 | test
then you can have access the using join.
I hope this helps