我有 3 张桌子。
PK table
- company
FK table
- staff
- machines
Table Data:
Company:
ID | NAME
1 | FLY RESORTS
Staff:
ID(fk) | NAME
1 | John Doe
1 | Johny Doe
Machines:
ID(fk) | NAME
1 | Bulldozer
1 | Helicopter
1 | Lorry
我写了 PDO 选择计数代码:
$keyword = "%" . $_GET["keyword"] . "%" ;
$sql = "SELECT count(*) FROM `company` INNER JOIN staff ON staff.ID = company.ID INNER JOIN machines ON machines.ID = company.ID WHERE (comp.name like '$keyword' or machines.name like '$keyword' or staff.name like '$keyword')";
$result = $conn->prepare($sql);
$result->execute();
$numrows = $result->fetchColumn();
当我将 设置为$keyword
时'fly'
,它会返回具有相同公司名称的多个结果计数/行。
我的代码有问题吗?谢谢