【问题标题】:SELECT all the rows which contains a specific keyword PHP选择包含特定关键字 PHP 的所有行
【发布时间】:2018-11-14 05:09:24
【问题描述】:

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

例如,数据库中有一个值为“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";
               }
       }

?>

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

有什么建议吗?

【问题讨论】:

标签: php mysql mysqli prepared-statement


【解决方案1】:
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."%")); 

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 2012-01-27
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多