嗨,我有 2 个结构如下的表
cdr
src | bill sec | clean_dst
------------------------------
100 | 10 | 18006927753
100 | 22 | 18006927753
100 | 9 | 441138973356
dialing_codes
id | dial_code | tele2id
-----------------------------
1 | 1 | 1422
2 | 1800 | 1433
3 | 441 | 1024
4 | 4413 | 1086
我需要获得 tele2id 以在 dial_code 中与 clean_dst 进行最接近的匹配,到目前为止我的最大努力是
$query = "SELECT tele2id, dial_code FROM dialing_codes ORDER by dial_code DESC";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
while($row = $result->fetch_assoc()) {
$tele2id = $row['tele2id'];
$dialcode = $row['dial_code'];
$query2 = "SELECT clean_dst FROM cdr WHERE clean_dst LIKE '".$dialcode."%'";
$result2 = $mysqli->query($query2) or die($mysqli->error.__LINE__);
while($row2 = $result2->fetch_assoc()) {
我认为这是可行的,但经过仔细检查,如果重复 clean_dst,它只会在第一次返回正确的结果
例如
clean_dst dial_code tele2id
18006927753 1800 1433
18006927753 1 1422
我究竟做错了什么?谢谢
如果它有帮助,我需要最匹配数字的结果?