如何在Angular 4中将表中的值传递给PHP文件中的查询

时间:2018-07-07 06:00:16

标签: php angular angular4-httpclient

我正在Angulars 4中创建一个应用程序。我正在使用PHP连接前端和后端

问题:我有4个表,一个是主表,另一个是明细表

主表具有以下列

  

表列:患者ID,姓名,年龄

它包含一个按钮,单击“查看”后,“查看患者ID”应传递给其余3个表格PHP文件中的SQL查询并查看相关的“患者值”

这是Other table PHP代码,我想调用Patient ID来查看其他表中的数据

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

$conn = new mysqli("localhost","root","password","metropolis");
$PatientID = $_POST['PatientID'];

$query = "SELECT `PatientID`, `Communication`, `Outcomes`, `Date` FROM metropolis.pareto_communication where `PatientID`='".$PatientID."';";

$result = $conn->query($query);
/*echo($query);
/*if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo("Connected successfully");*/


$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "") {$outp .= ",";}
    $outp .= '{"PatientID":"'  . $rs["PatientID"] . '",';
    $outp .= '"Communication":"'   . $rs["Communication"]        . '",';
    $outp .= '"Outcomes":"'   . $rs["Outcomes"]        . '",';
    $outp .= '"Date":"'   . $rs["Date"]        . '"}';
   /* $outp .= '"CallDetails":"'   . $rs["Time"]        . '"}';*/
}
$outp ='['.$outp.']';
$conn->close();

echo($outp);
?>

这是TS代码文件:

    getAllPatient(): any {
    this.isUpdateSuccess = "";
    this.api.getAll()
    .subscribe(res => this.patientList = res,
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
    this.selectedPatient = {"PatientID":"0","Name":"","Country":""};
  }
  getAllCommunication(): any {
    this.isUpdateSuccess = "";
    this.api.getAllCommunication()
    .subscribe(res => this.communicationList = res,
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
  // this.selectedPatient = {"Id":"0","Name":"","Country":""};
  }
  getAllVisits(): any {
    this.isUpdateSuccess = "";
    this.api.getAllVisits()
    .subscribe(res => this.visitsList = res,
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
  // this.selectedPatient = {"Id":"0","Name":"","Country":""};
  }
  getAllValues(): any {
    this.isUpdateSuccess = "";
    this.api.getAllValues()
    .subscribe(res => this.valuesList = res,
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
  // this.selectedPatient = {"Id":"0","Name":"","Country":""};
  }
  showPatientDetails(PatientID:String) {
  this.selectedPatient = _.find(this.patientList, {"PatientID":PatientID});
  console.log(this.selectedPatient);
  }
  showCommunicationDetails(PatientID:String) {
  this.selectedPatient = _.find(this.communicationList, {"PatientID":PatientID});
  console.log(this.selectedPatient);
  }
  saveComments(){
    this.isUpdateSuccess = "updating...";
    console.log(this.selectedPatient);
    let formsBody = "PatientID=" + this.selectedPatient.PatientID+ "&iscompleted=0&comments=" + this.selectedPatient.Source;
    this.api.save(formsBody)
    .subscribe(res => {
      console.log(res);
      this.isUpdateSuccess = "updated successfully";
    },
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
  }
  close(PatientID:String){
    this.isUpdateSuccess = "updating...";
    let closePatient = _.find(this.patientList, {"PatientID:String":PatientID:String});
    console.log(closePatient);
    let formsBody = "PatientID=" + closePatient.PatientID+ "&iscompleted=1&comments=" + closePatient.Source;
    this.api.save(formsBody)
    .subscribe(res => {
      console.log(res);
      this.getAllPatient();
      this.isUpdateSuccess = "updated successfully";
    },
        error => console.log(`Server error: ${error.status} - Details: ${error.error}`));
  }

}

问题是患者ID没有将值传递给查询该如何解决此问题

0 个答案:

没有答案