我试图回应特定用户信息的内容。我目前正在使用
int
12号将仅回显ID#12患者的内容。我如何能够回显任何用户信息的内容。换句话说,我还想单独回应用户13,14,15等的内容。我需要将“12”放到“GET”当前正在查看的用户的ID中。
我现在可以通过输入以下内容使用PHP来执行此操作:
$sql = "SELECT treatment_log.tech,treatment_log.comments FROM customers LEFT OUTER JOIN treatment_log ON customers.id=treatment_fk WHERE customers.id = 12";
答案 0 :(得分:4)
首先,将customer_id
保留在变量中。请记住,GET
不应与任何敏感数据一起使用。但是,正如您所要求的那样,也许您已经意识到这一点。如下所示:
$cid = $_GET['customer_id'];
然后使用?
符号代替12
编写sql查询,如下所示:
$sql = "SELECT treatment_log.tech,treatment_log.time,treatment_log.date,treatment_log.titration_parameter,treatment_log.pain,treatment_log.bdi,treatment_log.suicidality,treatment_log.comments FROM customers LEFT OUTER JOIN treatment_log ON customers.id=treatment_fk WHERE customers.id = ?";
然后执行以下操作:
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "s", $cid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
要了解上述每一行,请阅读官方手册
mysqli_stmt_init()
,mysqli_stmt_prepare()
,mysqli_stmt_bind_param()
,mysqli_stmt_execute()
,mysqli_stmt_get_result()
最后,要获得结果,请使用以下内容:
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "id: ". $row["tech"]. " " . $row["time"]." " . $row["date"]." " . $row["titration_parameter"]." " . $row["bdi"]." " . $row["suicidality"]." " . $row["comments"]. "<br>";
}
}
else {
echo "0 results";
}