コードで発生する問題がありますが、phpmyadmin でクエリをテストすると、NULL
(想定どおり) が表示されます。
いくつかのテーブルを結合して、ユーザーに関するすべての情報を表示したいと考えています。user テーブルには、クライアントに関する基本情報が含まれています。私のページでは、ユーザーの可能な医師の訪問、理学療法士の訪問、および専門家による治療に関する情報を追加したいと考えています。すべての接続は、次のように異なるテーブルに格納されます。
+------+-------------+--------------+
| n_id | n_client_id | n_connect_id |
+------+-------------+--------------+
| 1 | 1 | 1 |
+------+-------------+--------------+
| 2 | 1 | 2 |
+------+-------------+--------------+
n_connect_id
一致するテーブルに格納されている医師の理学療法士および/または専門家の記録の ID のいずれかです。
すべてのユーザーが 3 つ (医師、理学療法士、および専門家) のテーブルすべてにレコードを持っているわけではないため、場合によってNULL
は が出力されます。
phpmyadmin でクエリをテストすると$client = 1;
、次の出力が得られます (医師の診察は にのみ適用されるため、これは正しいですclient_id 1
)。
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
| clientId | clientName | clientAddres | clientZip | clientCity | clientPhone | clientMail | clientDoctorCompany | clientDoctor | clientPhysioCompany | clientPhysio | clientSpecialist | clientSpecialistsSpecialities | clientDoctorRecords | clientDoctorRecordsDate | clientDoctorRecordsParaph |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
| 1 | Name | Address 1 | 1234 AB | City | 0612345678 | info@url.com | Company 1 | Doctor 1 | Physio Company 1 | Therapist 1 | Specialist 1 | specialty 1, specialty 2 | visit 1 | 2012-11-11 | MK |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
phpmyadmin でクエリをテストすると$client = 2;
、次の出力が得られます (医師の診察は にのみ適用されるため、これは正しいですclient_id 1
)。
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
| clientId | clientName | clientAddres | clientZip | clientCity | clientPhone | clientMail | clientDoctorCompany | clientDoctor | clientPhysioCompany | clientPhysio | clientSpecialist | clientSpecialistsSpecialities | clientDoctorRecords | clientDoctorRecordsDate | clientDoctorRecordsParaph |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
| 1 | Name | Address 1 | 1234 AB | City | 0612345678 | info@url.com | Company 1 | Doctor 1 | Physio Company 1 | Therapist 1 | Specialist 1 | specialty 1, specialty 2 | NULL | NULL | NULL |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
私のウェブサイトでコードを実行すると、常にすべてのレコードが出力されます。$client
これは私が使用するコードです
<?php
class ClientData{
public $clientId;
public $clientName;
public $clientAddress;
public $clientZip;
public $clientCity;
public $clientPhone;
public $clientMail;
public $clientDoctor;
public $clientDoctorCompany;
public $clientDoctorRecords;
public $clientDoctorRecordsDate;
public $clientDoctorRecordsParaph;
public $clientPhysio;
public $clientPhysioCompany;
public $clientSpecialist;
public $clientSpecialistsSpecialities;
}
class clientManagement{
public $cInfo = Array();
public $clientInfo = Array();
public $querystring;
[..]
public function getClientDetails($client){
$dbdata = new mySQLAccessData();
$db = new PDO($dbdata->hostname,$dbdata->username,$dbdata->password);
$sql = "
SELECT
client.c_id AS clientId, client.c_name AS clientName, client.c_address AS clientAddress, client.c_zip AS clientZip, client.c_city AS clientCity, client.c_tel AS clientPhone, client.c_mail AS clientMail,
doctorCompany.d_name AS clientDoctorCompany,
doctor.d_name AS clientDoctor,
physioCompany.p_name AS clientPhysioCompany,
physio.p_name AS clientPhysio,
specialist.s_name AS clientSpecialist,
GROUP_CONCAT(DISTINCT specialities.s_specialty) AS clientSpecialistsSpecialities,
GROUP_CONCAT(DISTINCT dvr.dv_records) AS clientDoctorRecords,
GROUP_CONCAT(DISTINCT dvr.dv_datetime) AS clientDoctorRecordsDate,
GROUP_CONCAT(DISTINCT dvr.dv_paraph) AS clientDoctorRecordsParaph
FROM adm_clients AS client
LEFT JOIN norm_client_doctor AS ncd ON ncd.ncd_client_id = client.c_id
LEFT JOIN adm_doctor_company AS doctorCompany ON doctorCompany.d_id = ncd.ncd_doctor_id
LEFT JOIN norm_doctor_company AS ndc ON ndc.ndc_company_id = doctorCompany.d_id
LEFT JOIN adm_doctor_person AS doctor ON doctor.d_id = ncd.ncd_doctor_id
LEFT JOIN adm_doctor_visit_records AS dvr ON dvr.dv_client_id = client.c_id
LEFT JOIN norm_client_physio AS ncp ON ncp.ncf_client_id = client.c_id
LEFT JOIN adm_physiotherapist_company AS physioCompany ON physioCompany.p_id = ncp.ncf_physio_id
LEFT JOIN norm_physio_company AS npc ON npc.nfc_company_id = physioCompany.p_id
LEFT JOIN adm_physiotherapist_person AS physio ON physio.p_id = npc.nfc_physio_id
LEFT JOIN norm_client_specialist AS ncs ON ncs.ncs_client_id = client.c_id
LEFT JOIN adm_specialist_person AS specialist ON specialist.s_id = ncs.ncs_specialist_id
LEFT JOIN norm_specialist_specialities AS nss ON nss.nsc_company_id = specialist.s_id
LEFT JOIN adm_specialist_specialities AS specialities ON specialities.s_id = nss.nsc_specialist_id
WHERE client.c_id = '".$client."'
";
$result = $db->query($sql);
$obj = $result->setFetchMode(PDO::FETCH_INTO, new ClientData);
$i = 0;
foreach($result as $show){
$i++;
$this->clientInfo[$i] = new ClientData();
$this->clientInfo[$i]->clientId = $show->clientId;
$this->clientInfo[$i]->clientName = $show->clientName;
$this->clientInfo[$i]->clientAddress = $show->clientAddress;
$this->clientInfo[$i]->clientZip = $show->clientZip;
$this->clientInfo[$i]->clientCity = $show->clientCity;
$this->clientInfo[$i]->clientPhone = $show->clientPhone;
$this->clientInfo[$i]->clientMail = $show->clientMail;
$this->clientInfo[$i]->clientDoctor = $show->clientDoctor;
$this->clientInfo[$i]->clientDoctorCompany = $show->clientDoctorCompany;
$this->clientInfo[$i]->clientDoctorRecords = $show->clientDoctorRecords;
$this->clientInfo[$i]->clientDoctorRecordsDate = $show->clientDoctorRecordsDate;
$this->clientInfo[$i]->clientDoctorRecordsParaph = $show->clientDoctorRecordsParaph;
$this->clientInfo[$i]->clientPhysioCompany = $show->clientPhysioCompanyclientDoctorRecordsParaph;
$this->clientInfo[$i]->clientPhysio = $show->clientPhysio;
$this->clientInfo[$i]->clientSpecialist = $show->clientSpecialist;
$this->clientInfo[$i]->clientSpecialistsSpecialities = $show->clientSpecialistsSpecialities;
}
}
public function displayClientDetails(){
$output = '<h3>Klantgegevens</h3>
<div id="clientInfoContainer">
<div id="clientStaticInfo">
<p><img src="'._BACKEND_URL.'/Inc/Im/icons/user_64.png" class="userImage"></p>
<p><small>Klant aangemaakt op 10/12/2012</small></p>
<p><small>Laatste wijziging op 10/12/2012</small></p>
</div>
<div id="clientDynamicInfo">
<table id="clientInfoTable">
<colgroup>
<col class="tableLabel">
<col class="tableValue">
</colgroup>
<thead>
<tr>
<th>Label</th>
<th>Waarde</th>
</tr>
</thead>
<tbody>
<tr>
<td>Naam</td>
<td>'.$this->clientInfo[1]->clientName.'</td>
</tr>
<tr>
<td>Adres</td>
<td>'.$this->clientInfo[1]->clientAddress.'</td>
</tr>
<tr>
<td>Postcode woonplaats</td>
<td>'.$this->clientInfo[1]->clientZip.' '.$this->clientInfo[1]->clientCity.'</td>
</tr>
<tr>
<td>Telefoonnummer</td>
<td>'.$this->clientInfo[1]->clientPhone.'</td>
</tr>
<tr>
<td>Email</td>
<td>'.$this->clientInfo[1]->clientMail.'</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="physio-visit-list" class="collapseContainer">
<h4>Praktijk fysiotherapie: <strong>'.$this->clientInfo[1]->clientPhysioCompany.'</strong>. Behandelend arts: <strong>'.$this->clientInfo[1]->clientPhysio.'</strong></h4>
<div class="collapsableContent">
<p>'.$this->clientInfo[1]->clientSpecialistsSpecialities.'</p>
</div>
</div>
<div id="doctor-visit-list" class="collapseContainer">
<h4>Dokterspraktijk: <strong>'.$this->clientInfo[1]->clientDoctorCompany.'</strong>. Behandelend arts: <strong>'.$this->clientInfo[1]->clientDoctor.'</strong></h4>
<div class="collapsableContent">
<p>'.$this->clientInfo[1]->clientDoctorRecords.'</p>
</div>
</div>
';
echo($output);
}
}
?>
問題は行のどこかにあると思いLEFT JOIN adm_doctor_visit_records AS dvr ON dvr.dv_client_id = client.c_id
ます。これは、医師の診察記録を保存するテーブルであるためです。私は user_id だけで参加したと思っていましたが、どうやらここで何かがおかしいようです。
PS、私はOOPを始めたばかりなので、間違った方法で行っている場合、これが私が理解している方法です(ただし、提案は受け付けています)