当用户键入包含在表中原始数据中的单词时,我需要显示数据库中的所有结果。
作为一个实例,数据库中有一个值为“Alabaster25_24x18”的元组。
因此,当用户键入“Ala”或“Alab”或“Alabas”时,应检索此元组,并应检索包含 Alabaster 关键字的其他元组。
我已经为此编写了一个代码块。
<form action="" method="POST">
Board Code: <input name="job_no" type="text" /> </br>
Material Description : <input name="client_ref" type="text" /></br>
Thickness: <input name="thickness" type="text" /></br>
<button type="submit" name="submit">Submit</button>
</form>
<?php
if(isset($_POST["submit"])){
$servername="localhost";
$username = "root";
$password = "";
$dbname = "db";
$conn = new mysqli($servername,$username,$password,$dbname);
if(!$conn){
die('Not connected : ' . mysql_error());
}
if (!function_exists('bind_array')) {
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
}
$job_no = $_POST["job_no"];
$client_ref = $_POST["client_ref"];
$thickness= $_POST["thickness"];
if(empty($job_no) ){
echo "Input at least one data";
}else if(empty($client_ref)){
$Query = Database::Prepare("SELECT * FROM new_jobs WHERE thickness LIKE ?");
$Query->Execute(array("%".$job_no."%"));
while($query->fetch()){
echo "The Promised Date is ".$row[$Query];
}
}else{
// echo "koihgygyugui";
}
}
?>
不幸的是,它没有得到预期的结果。
有什么建议吗?
最佳答案
Board Code: <input name="job_no" type="text" /> </br>
Material Description : <input name="client_ref" type="text" /></br>
Thickness: <input name="thickness" type="text" /></br>
....
$Query = Database::Prepare("SELECT * FROM new_jobs WHERE thickness LIKE ?");
$Query->Execute(array("%".$job_no."%"));
您应该传递厚度作为参数吗?
$Query = Database::Prepare("SELECT * FROM new_jobs WHERE thickness LIKE ?");
$Query->Execute(array("%".$thickness."%"));
关于php - SELECT 包含特定关键字 PHP 的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53293529/