我的数据库里有两个表, tb_device
以及 tb_label
其中包含以下内容,例如:
tb_device
id (AI) | type | label | etc
-------------------------------------
1 | A123 | 1 | test
2 | A561 | 3 | test2
3 | A777 | 2 | test3
4 | A222 | 3 | test4
tb_label
id (AI) | label
-------------------
1 | Samsung
2 | Apple
3 | Dell
我已经创建了crud表单(php)来显示 tb_devices
. 这个crud在每一列上都有一个搜索表单。其他列用于搜索,但标签列不工作,因为它包含 id
从 tb_label
. 我想搜索标签名称如下的标签 samsung
, apple
, dell
,不是数字。我的搜索代码:
$sql = "SELECT *
FROM tb_device a, tb_label b
WHERE
type LIKE '%".@$_POST['type']."%' AND
(a.label=b.id AND b.label LIKE '%".@$_POST['label']."%') AND
etc LIKE '%".@$_POST['etc']."%'
ORDER BY type
";
我试着输入 dell
,但结果是:
3 | A777 | 2 | test3
说明: dell
有 id
数字 3
,结果显示 id
数字 3
从 tb_device
. 有没有解决办法来显示正确的结果?
对不起,英语不好
2条答案
按热度按时间r1zk6ea11#
我认为您应该只有where for tb\u label.label=(您的用户输入变量:dell)
我相信你想做一个
8yoxcaq72#
查询中缺少b.label