【问题标题】:Multiple SQL queries to select data MySql php多个 SQL 查询以选择数据 MySql php
【发布时间】:2017-12-15 06:06:50
【问题描述】:

我有很多表,我需要从那里选择数据并显示在我的 HTML 表中。

我现在需要执行两个查询才能显示所有结果。

但是,我只能在我的代码中放置一个查询。我的代码如下:

<?php
$stmt = $DB_con->prepare("SELECT * FROM applicantpersonaldetails apd "
        . "INNER JOIN employementdetails ed ON apd.ApplicantID = ed.ApplicantID "
        . "INNER JOIN sourceoffunds sof ON apd.ApplicantID = sof.ApplicantID "
        . "WHERE apd.AccountID =:accountId AND apd.applicantType ='main';");


$stmt->bindParam(':accountId', $accountId, PDO::PARAM_INT);
$stmt->execute();
if ($stmt->rowCount() > 0) {
    ?>                                    


    <table id="01">

        <tr>
            <th></th>
            <th>Main Applicant</th>
            <th>Joint Applicant1</th>

        </tr>
        <?php
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            ?>
            <tr>
                <td>Name</td>
                <td><input name="nameMain"></td>
                <td><input name="nameJoint1"></td>

            </tr>
            <tr>
                <td>Occupation</td>
                <td><input type="text" id="occupationMain" name="occupationMain" value="<?php echo $row['EmploymentStatus']; ?>" readonly></td>
                <td><input type="text" id="occupationJoint1" name="occupationJoint1" value="" readonly></td>
            </tr>
            <tr>
                <td>Employment</td>
                <td>
                    <div>
                        <input list="employTypeList" name="employTypeMain" id="employTypeMain" value="" readonly>
                    </div>
                </td>
                <td>
                    <input list="employTypeList" name="employTypeJoint1" id="employTypeJoint1" value="" readonly >

                </td>
            </tr>
            <tr>
                <td>Company</td>
                <td><input type="text"   id="companyMain" name="companyMain" value="" readonly></td>
                <td><input type="text"   id="companyJoint1" name="companyJoint1" value=""readonly></td>
            </tr>

        </table>
        <?php
    }
} else {
    ?>
    <div class="">
        <div class="alert alert-warning">
            <span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ...
        </div>
    </div>
<?php }
?>

现在,我想在我的代码中插入另一个 SQL 查询,以显示 joint1 的结果

另一个查询如下:

    $stmt = $DB_con->prepare("SELECT * FROM applicantpersonaldetails apd "
            . "INNER JOIN employementdetails ed ON apd.ApplicantID = ed.ApplicantID "
            . "INNER JOIN sourceoffunds sof ON apd.ApplicantID = sof.ApplicantID "
            . "WHERE apd.AccountID =:accountId AND apd.applicantType ='joint1';");
$stmt->bindParam(':accountId', $accountId, PDO::PARAM_INT);
$stmt->execute();

【问题讨论】:

    标签: php html mysql sql database


    【解决方案1】:

    它们是相同的查询,只是寻找不同的申请人类型,所以只需使用 AND apd.applicantType IN ('main','joint1')

    【讨论】:

    • 数据在同一张表下,如何确保另一列获取的是joint1的数据?
    猜你喜欢
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 2012-02-01
    • 1970-01-01
    相关资源
    最近更新 更多