php - Mysql搜索条件为两行
问题描述
在表中搜索时引入了一个条件
$sql = "SELECT id,email FROM employee WHERE email LIKE ?";
在代码中需要添加条件id='12'
更多代码请查看以下代码
if(isset($_REQUEST["term"])){
// Prepare a select statement
$sql = "SELECT id,email FROM employee WHERE id='12' AND email LIKE ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
// Set parameters
$param_term = '%'. $_REQUEST["term"] . '%';
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
// Check number of rows in the result set
if(mysqli_num_rows($result) > 0){
// Fetch result rows as an associative array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo "<p>" . $row["email"] . "</p>";
}
} else{
echo "<p>No matches found</p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
// Close statement
mysqli_stmt_close($stmt);
}
解决方案
试试这个
$sql = "SELECT id,email FROM employee WHERE id='12' AND email LIKE ?";
更改代码
// Set parameters first of all
$param_term = '%'. $_REQUEST["term"] . '%';
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
推荐阅读
- apache-kafka - 注册 Avro 模式时出错:写入 Kafka 存储时注册模式操作失败;错误代码:50001
- php - CURLOPT_CAINFO/CAPATH 究竟是什么?
- c++ - 如何在 GTK3 上强制 CORE opengl 配置文件?(#版本 330)
- .net - 生成源代码哈希的最佳方法是什么?
- javascript - 无法在我的 HTML 页面上显示另一个 Highcharts 图表 - Django
- javascript - Math.random() 结果的位数
- regex - 如何使用正则表达式在引用文本中提取多个符号/子字符串
- ios - 如何重新创建 dSYM
- android - 如何在没有 Sceneform 的情况下使用 ARCore 和 OpenGL 显示和锚定文本?
- python - Exporting large array variables (type = object) to CSV files