我有一个MySQL查询,该函数将转录器表中的数据与列出其认证的表中的数据相结合。一些转录员可能拥有多个认证。
我发现有些抄录员应该为自己拥有的每份证书提出一次。对于其他记录器,第一个数组值将被第二个数组值覆盖。在我看来,如果转录器具有两个证书,一个证书具有certId 1,一个证书具有certId 3,则三个证书将覆盖1。这对于certId为2、4、5、6或7(任意组合)不会发生除了1和3)。
这是我的代码:
public function getTranscribersAndTheirCertificationsList() {
$Q = $this->read_db->query('SELECT t.*, tc.certId, tc.regNum, c.certName FROM transcriber t
JOIN transcribercertifications tc ON t.id = tc.tid
JOIN certifications c ON tc.certId = c.id');
return $Q->result_array();
}
下面的代码接收从上面传入的数据并进行处理:
$list = $this->MTranscriber->getTranscribersAndTheirCertificationsList();
foreach ($list as $t) {
$key = explode(' ', trim($t['name']));
$key = preg_replace('/[()]/','', $key);
$key = array_reverse($key);
$key = implode(' ', $key) . $t['id'];
$t['cet'] = $t['certName'] . ($t['regNum'] ? '-' . $t['regNum'] : '');
if ($t['certId'] == 2 || $t['certId'] == 5) {
$data['cetlist']['tta'][$key] = $t;
} else {
$data['cetlist']['cet'][$key] = $t;
}
}
if (!empty($data['cetlist']['cet'])) {
ksort($data['cetlist']['cet']);
}
if (!empty($data['cetlist']['tta'])) {
ksort($data['cetlist']['tta']);
}
如果回显$ t,数据看起来不错。由于某些原因,当$ t被添加到else分支的每个数组中时,在certId = 1和certId = 3的情况下,第一个值被覆盖。我尝试使用array_push和array_merge,但未获得结果我也需要
编辑这是一些消毒的数据:
Array
(
[Doe John9] => Array
(
[id] => 9
[name] => John Doe
[email] =>
[homephone] =>
[cellphone] =>
[address1] => 1 Main Street
[address2] =>
[city] => ABC
[stateregion] =>
[zipcode] => 99999
[cet] => CET-485
[certId] => 3
[regNum] => 485
[certName] => CET
)
)
如果John Doe拥有另一份certId为1(CER)的证书,则上面的数据将覆盖它,而我只得到上面的数据。我应该为CER获得一份,为CET获得一份。
用于将转录器保存到阵列的密钥与certId相同。因此,您将始终覆盖先前的条目。如果要添加转录器的多个版本,则应将certId添加到密钥中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句