选择所有包含特定关键字PHP

时间:2018-11-14 05:09:24

标签: php mysql mysqli prepared-statement

当用户键入表中原始数据中包含的单词时,我需要在数据库中显示所有结果。

作为一个实例,数据库中有一个元组,其值为“ 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";
               }
       }

?>

不幸的是,它没有得到预期的结果。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

const SubDocumentSchema = new mongoose.Schema({
  content: {
    type: String,
    trim: true
  },
  date: {
    type: Date,
    default: Date.now
  }
})

const DocumentSchema = new mongoose.Schema({
  notes: {
    type: [SubDocumentSchema],
    default: []
  }
});

const Document = mongooseConnection.model('DocumentSchema', DocumentSchema)
const t = new Document()

t.save()

您应该将“厚度”作为参数传递吗?

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."%"));