Reputation: 211
The problem that I am having now is that I will be getting duplicated data if My MySql tables have the data inside. However, if one of my tables is empty, all data is not able to be shown.
This is my code below:
$stmt = $DB_con->prepare("SELECT * FROM applicantpersonaldetails apd "
. "JOIN employementdetails ed ON apd.ApplicantID = ed.ApplicantID "
. "JOIN sourceoffunds sof ON apd.ApplicantID = sof.ApplicantID "
. "JOIN existingbankproducts ext ON apd.ApplicantID = ext.ApplicantID "
. "WHERE apd.AccountID ='{$accountId}' AND applicantType ='joint1';");
$stmt->execute();
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
echo $row['EmploymentStatus'];
?>
<?php
}
} else {
?>
<div class="">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
Upvotes: 0
Views: 31
Reputation: 1271003
Use a LEFT JOIN
if you want all rows, even non-matching ones:
SELECT *
FROM applicantpersonaldetails apd LEFT JOIN
employementdetails ed
ON apd.ApplicantID = ed.ApplicantID LEFT JOIN
sourceoffunds sof
ON apd.ApplicantID = sof.ApplicantID LEFT JOIN
existingbankproducts ext
ON apd.ApplicantID = ext.ApplicantID
WHERE apd.AccountID ='{$accountId}' AND applicantType = 'joint1';
Note: It is not clear which table applicantType
comes from. If it is not from apd
, then you might want to include it in the appropriate ON
clause rather than in the WHERE
clause.
Upvotes: 2