如何分隔 mysql 数据库行中的每一列?在 laravel
how to separate each and every column in the mysql db row ? in laravel
控制器
public function getback(Request $request)
{
$chart = DB::table('BirthChart_1')
->where('FileId', 123)
->get();
return $chart;
}
输出类似于
[{"FileId":123,"k1":3,"k2":4,"k3":null,"k4":null,"k5":null,"k6":5,"k7":null,"k8":null,"k9":null,"k10":null}]
我想分别访问每一列,我是这样写的
return $chart["k1"];
遇到错误...
my main task is take the each column's data send into script
您正在获取行数组,请尝试:
return $chart[0]["k1"];
控制器就像
public function getback(Request $request)
{
$chart = DB::table('BirthChart_1')
->where('FileId', 123)
->get();
foreach ($chart as $key ) {
$f[] = [$key->k1,$key->k2,$key->k3,$key->k4,$key->k5,$key->k6,$key->k7,$key->k8,$key->k9,$key->k10];
}
return response()->json($f);
}
输出结果
[[3,4,null,null,null,5,null,null,null,null]]
控制器
public function getback(Request $request)
{
$chart = DB::table('BirthChart_1')
->where('FileId', 123)
->get();
return $chart;
}
输出类似于
[{"FileId":123,"k1":3,"k2":4,"k3":null,"k4":null,"k5":null,"k6":5,"k7":null,"k8":null,"k9":null,"k10":null}]
我想分别访问每一列,我是这样写的
return $chart["k1"];
遇到错误...
my main task is take the each column's data send into script
您正在获取行数组,请尝试:
return $chart[0]["k1"];
控制器就像
public function getback(Request $request)
{
$chart = DB::table('BirthChart_1')
->where('FileId', 123)
->get();
foreach ($chart as $key ) {
$f[] = [$key->k1,$key->k2,$key->k3,$key->k4,$key->k5,$key->k6,$key->k7,$key->k8,$key->k9,$key->k10];
}
return response()->json($f);
}
输出结果
[[3,4,null,null,null,5,null,null,null,null]]