-3

我在我的数据库中创建了一个诊所表,其中包含诊所的详细信息,例如。ClinicID(主键)、姓名、地址、电子邮件等。我有另一个名为 Doctor 的表,它根据 ClinicID 列出诊所中医生的姓名。问题是,在一个诊所中,每个诊所可能有超过 1 名医生。如何在 html 表格中显示诊所的详细信息,该表格将列出所有详细信息,包括诊所可用的所有医生?

诊所表

clinicID
name
address
email

医生桌

clinicID
nameOfDoctor
4

3 回答 3

0
select nameOfdoctor from Doctor where ClinicId=1

将向您显示诊所 1 的医生名单

于 2013-04-02T16:38:25.177 回答
0

您必须拨打两次电话来整理每个查询中的信息:

$raw_clinics = //sql query to get clinic data
$doctors = //sqlquery to get doctors data
$clinics = array();

foreach($raw_clinics as $c) {
    $clinics[$c['clinicID']] = $c;
}

foreach($doctors as $d) {
    if (!isset($clinic[$d['clinicID']]['doctors'])) $clinic[$d['clinicID']]['doctors'] = array();
    $clinic[$d['clinicID']]['doctors'][] = $d;
}
于 2013-04-02T16:39:48.297 回答
0

你需要两个迭代循环来得到这个(假设你想要一个诊所列表):

$clinicResult = $mysqli->query("SELECT * FROM Clinic");
while ($clinicData = $clinicResult->fetch_assoc()) {
    //Insert your HTML statements regarding clinic details here
    $doctorResult = $mysqli->query("SELECT * FROM Doctor WHERE clinicID = ".$clinicData['clinicID']);

    while ($doctorData = $doctorResult->fetch_assoc() {
        //Insert your HTML statements regarding doctors here
    }
}
于 2013-04-02T16:44:34.010 回答