I have a problem that occurs in my code, but when i test the query in phpmyadmin i get NULL (like it’s supposed to be)
I want to join a couple of tables to display all information about a user. The user table contains the basic information about a client. On my page i want to add information about a users possible doctor visits, physiotherapist visits and treatments by specialist. Every connection is stored in a different table, like so:
+------+-------------+--------------+
| n_id | n_client_id | n_connect_id |
+------+-------------+--------------+
| 1 | 1 | 1 |
+------+-------------+--------------+
| 2 | 1 | 2 |
+------+-------------+--------------+
n_connect_id can either be the id of the doctor's- physiotherpist's and/or specialist's record that is stored in the matching tables.
Because not all users will have records in all three (doctors, physiotherapists and specialist) tables, so in some cases NULL will be the output.
When i test my query in phpmyadmin with $client = 1; i get the following output (which is correct since the doctor's visits only apply to 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 |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
When i test my query in phpmyadmin with $client = 2; i get the following output (which is correct since the doctor's visits only apply to 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 |
+----------+------------+---------------+-----------+------------+-------------+--------------+---------------------+--------------+---------------------+--------------+------------------+-------------------------------+---------------------+-------------------------+---------------------------+
When i run the code on my website it constantly outputs all the records, no mather if i change the $client
This is the code i use
<?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);
}
}
?>
I assume the problem is somewhere iin the line LEFT JOIN adm_doctor_visit_records AS dvr ON dvr.dv_client_id = client.c_id, since that's the table that stores the doctor visit records. I thought i joined it only on the user_id but apparently something's going wrong here.
PS, i just started OOP so if i'm doing it the wrong way, this is the way i understand it (open for suggestions though)
Aah.. solved it, was somehow passing a wrong parameter via
$client. Weird how it could happen though. Thanks for the help!