我想在两个表中搜索,但没有得到即时结果。这是我的代码。
$query=mysqli_query($db_connection,"SELECT * FROM db_clients JOIN db_deadreg ON db_clients.clientID=db_deadreg.clientID where fullname like '%$searchq%'");
答案 0 :(得分:0)
您可以使用concat构建适当的过滤器
$query=mysqli_query($db_connection,
"SELECT *
FROM db_clients
JOIN db_deadreg ON db_clients.clientID=db_deadreg.clientID
where fullname like concat('%' , $searchq , '%') ; ");
无论如何,您都不应该在SQL中使用php var,因为您有遭受sql注入的危险,您应该查看sql驱动程序中准备好的语句和bindig参数
例如:
$conn = new mysqli($servername, $username, $password, $dbname);
$stmt = $conn->prepare("SELECT *
FROM db_clients
JOIN db_deadreg ON db_clients.clientID=db_deadreg.clientID
where fullname like concat('%' , ? , '%')");
$stmt->bind_param("s", $searchq);
$stmt->execute();