gpt4 book ai didi

php - 如何查询外键并获取对应的行

转载 作者:行者123 更新时间:2023-11-29 13:13:32 25 4
gpt4 key购买 nike

我的 PHP 查询有问题。我只需要在 ListView 中获取点击的患者的处方即可。

这是处方的表结构。

enter image description here

enter image description here

我需要 ID 为 79 的患者显示他所有相应的处方。请帮助我。

这是 PHP。

<?php

/*
* Following code will list all the products
*/

// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

if (isset($_GET["uid"])) {
$uid = $_GET['uid'];

// get all products from products table

$result = mysql_query("select * from prescription") or die(mysql_error());

// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["prescription"] = array();

while ($row = mysql_fetch_array($result)) {
// temp user array
$prescription = array();
$prescription["pres_id"] = $row["pres_id"];
$prescription["pres_name"] = $row["pres_name"];
//$product["price"] = $row["price"];


// push single product into final response array
array_push($response["prescription"], $prescription);
}
// success
$response["success"] = 1;

// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No prescriptions found";

// echo no users JSON
echo json_encode($response);
}
}else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
}
?>

最佳答案

要获取选定患者的所有处方,不是吗:

mysql_query("select * from prescription where patient_user_fkey = '$patientID'")or die(mysql_error());

而不是:

mysql_query("select * from prescription") or die(mysql_error());

关于php - 如何查询外键并获取对应的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21793721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com