0

I need to show all the results in the database when the user types a word which includes in the original data in the table.

As an instance, there is a tuple in the database which has a value of "Alabaster25_24x18".

so when the user types "Ala" or "Alab" or "Alabas" this tuple should retrieve and other tuples which contain Alabaster keyword should retrieve.

I have written a code chunk for that.

 <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";
               }
       }

?>

Unfortunately, it is not getting the intended results.

Any suggestions?

e_i_pi
  • 4,590
  • 4
  • 27
  • 45
Simon
  • 195
  • 2
  • 4
  • 18
  • Share the sample table data. When you say tuple, it means comma separated data ? If that is true, well you need to normalize the table(s) first. – Madhur Bhaiya Nov 14 '18 at 05:18
  • Possible duplicate of [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Madhur Bhaiya Nov 14 '18 at 05:18

1 Answers1

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

Should you be passing Thickness as the parameter?

$Query = Database::Prepare("SELECT * FROM new_jobs WHERE thickness LIKE ?");
$Query->Execute(array("%".$thickness."%")); 
Paul Maxwell
  • 33,002
  • 3
  • 32
  • 51