例如,在哪里可以为@Ibu建议的解决方案设置一个限制?
$queried = mysql_real_escape_string($_POST['query']); // always escape
$keys = explode(" ",$queried);
$sql = "SELECT * FROM links WHERE name LIKE '%$queried%' ";
foreach($keys as $k){
$sql .= " OR name LIKE '%$k%' ";
}
$result = mysql_query($sql);
我尝试像这样在第二个$sql
变量上设置它:
$sql .= " OR name LIKE '%$k%' LIMIT 0, 20 ";
但是,这不会返回任何结果。预先感谢您的输入。
答案 0 :(得分:1)
您不应使用mysql函数,而应使用mysqli 但这就是您要寻找的
$sql = "SELECT * FROM links WHERE name LIKE '%$queried%' ";
foreach($keys as $k){
$sql .= " OR name LIKE '%$k%' ";
}
$sql .= "LIMIT 0, 20";
$result = mysql_query($sql);