【发布时间】:2018-07-04 05:11:17
【问题描述】:
我已经编写了一个代码来查看数据,但是我遇到了一些问题。
从代码中,我写它是从一个表中查看数据,即$details。但我也想查看 $detailsAns 中的数据。
我该怎么做?另外,我可以foreach这两个表中的两个数据吗?
我的代码如下:
public function queries($companyID, $entityType, $entityValue)
{
$data = [];
$details = DiraQuestion::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();
$detailsAns = DiraResponses::where('company_id', $companyID)->where('eType', $entityType)->where('eVal', $entityValue)->get();
foreach($details as $key => $detailsValue)
{
if(!array_key_exists($detailsValue->intent, $data))
{
$data[$detailsValue->intent] = [];
}
if(!array_key_exists($detailsValue->reply, $data[$detailsValue->intent]))
{
$data[$detailsValue->intent]['answer'][$detailsValue->reply] = $detailsValue->id;
}
if(!array_key_exists($detailsValue->queries, $data[$detailsValue->intent]))
{
$data[$detailsValue->intent]['question'][$detailsValue->queries] = $detailsValue->id;
}
}
ksort($data);
return view('AltHr.Chatbot.queries', compact('data','entityType','entityValue','companyID'));
}
如您所见,我可以为$details 返回来自foreach 的数据,但现在我也想返回$detailsAns 的数据。我该怎么做?
我的数据库结构:
所以要获取数据,它首先必须选择公司 ID、eType、eVal 和意图,因此现在我需要显示回复和查询。
如您所见,我可以在我所做的 foreach 中输出问题表。如果我将 foreach 更改为 $detailsAns 然后我会显示回复.. 但我现在想查看两者
【问题讨论】:
-
您能否将
$details和$detailsAns中的值连同您的预期输出一起包含在内 -
嗨@Miggy,请检查更新的问题
-
与您的
questions_table和response_table有任何关系吗?如果没有,我认为最好添加一个,因为答案数据应该连接到问题 -
不,这两个表之间不应该有任何关系。我只想查看页面上的两个数据..