将自动完成值拆分为2个字符串,用于php函数

时间:2019-05-09 08:50:46

标签: php jquery html

“自动完成”中的值是名字和姓氏。我需要将它们分为两个字符串,fnln,并将它们发送给PHP函数以计算结果。

我不确定如何将名称分成两个值并将其发送到另一个PHP函数,该函数计算这两个人之间的关系需要他们的名字和姓氏来确定其ID。

<html>
<?php include ('relation.php');?>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <script>
    $(function() {
      $("#fname").autocomplete({
        source: 'mysql.php'
      });
    });

    $(function() {
      $("#fname2").autocomplete({
        source: 'mysql.php'
      });
    });
  </script>
  <div class="ui-widget">
    <label for="skills">fist person: </label>
    <input id="fname">
  </div>
  <div class="ui-widget">
    <label for="skills">second person </label>
    <input id="fname2">
  </div>
  <div class="ui-widget">
    <label for="skills">Skills: </label>
    <button id="search" onclick="">
  </div>
?>
</html>
<?php
  //database configuration
  $dbHost = 'localhost:3308';
  $dbUsername = 'root';
  $dbPassword = '';
  $dbName = 'village';

  //connect with the database
  $db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);

  //get search term
  $searchTerm = $_GET['term'];

  //get matched data from skills table
  $query = $db->query("SELECT * FROM individual WHERE fname LIKE 
 '%".$searchTerm."%'");
  while ($row = $query->fetch_assoc()) {
    $data[] = $row['fname']." ".$row['lname'];
  }

  //return json data
  echo json_encode($data);
 ?>

//relation.php


function calculate_relationship($a_id, $b_id)



function aggrandize_relationship($rel, $dist, $offset = 0) {

function lowest_common_ancestor($a_id, $b_id)
function lowest_common_ancestor($a_id, $b_id)
function get_ancestors($id, $dist = 0)

.....

function getid($fname,$lname){
   $conn = OpenCon();
   get matched data from skills table
  $query = $conn->query("SELECT id FROM individual WHERE fname LIKE 
 '%".$fname."%' and lname LIKE '%".$lname."%'");
  $row = $query->fetch_row();


    return $row[0];8*/


   }
  if( $_GET['fn1'] && $_GET['ln1']&&$_GET['fn2'] && $_GET['ln2']) {



$relation=calculate_relationship(getid($_GET['fn1'],$_GET['ln1']),getid($_GET['f 
            n2'],$_GET['ln2']));
          } 



//$relation=calculate_relationship($_GET['fn1'],$_GET['fn2']);
if($relation!='')
echo   "  a is the " .$relation." of b ";

else
echo "There's no relation between a and b ";

0 个答案:

没有答案