2017-07-03 42 views
0

获取值我有一个像MySQL的 - 通过

enter image description here

我想记录,如

Array(
    'col-1' => ['v1','v4','v7'], 
    'col-2' => ['v2','v5','v8'], 
    'col-3' => ['v3','v6','v9'], 
) 

一个示例表有没有办法把它在MySQL

回答

1

从你列出你想要的输出的方式我猜你正在使用PHP。万一你有兴趣在一个更简单的基于PHP的解决您的问题,那就是:

$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); 
1

您好我认为你需要改变你的数据库结构

您可以创建两个表,例如

// Product Table i wish 
id | name 
--------- 
1 | test 
2 | Examplace product 

,那么你可以创建其他表

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 

那么你可以访问正在使用的连接。

我希望这可以帮助