具有公共列的多个表

时间:2016-04-09 13:28:25

标签: php mysql

我有一个名为“production_db”的数据库,里面有6个表。所有表格都有一个名为“dueDate”的 Common Column 。我创建了一个php页面,用户可以根据日期输入搜索所有表格,并将结果显示在一个页面中。下面的代码仅显示单个表的结果。

<div class="container" style="margin-top:100px">
    <legend><b>Search Delivery Date Schedule</b></legend>
    <form action="index.php" method="post" class="form-inline" role="form">
        <div class="form-group">
            <label for="">Search orders that are set to deliver on</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="text" class="form-control input-sm datepick" name="dueDate" style="text-align:center" value="<?php echo !empty($dueDate)?$dueDate:'';?>">
        </div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="form-group">
            <button class="btn-success form-control btn-sm">Search</button>
        </div>
    </form><br>

    <?php
        include 'pages/database.php';

        $dueDate = isset($_POST['dueDate']) ? $_POST['dueDate'] : '';

        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT * FROM aafes WHERE dueDate ='$dueDate'";
        $q = $pdo->prepare($sql);
        $q->execute(array($dueDate));
        $data = $q->fetch(PDO::FETCH_ASSOC);
        if (($data)==0) { 
            echo 'Search Results';

        } else {    
            echo '<table class="table table-striped table-bordered table-hover">'; 
            echo '<tr>';
                echo '<th style="text-align:center">Order No</th>';
                echo '<th style="text-align:center">Order Date</th>';
                echo '<th style="text-align:center">Delivery Date</th>';
                echo '<th style="text-align:center">Facility Name</th>';
                echo '<th style="text-align:center">Total Quantity</th>';
            echo '</tr>'; 
            foreach ($pdo->query($sql) as $row) {
            echo '<tr>';
                 echo '<td style="text-align:center" width="10%">'. $row['orderNo'] . '</td>';
                 echo '<td style="text-align:center" width="10%">'. $row['orderDate'] . '</td>';
                 echo '<td style="text-align:center" width="10%">'. $row['dueDate'] . '</td>';
                 echo '<td style="text-align:center" width="10%">'. $row['facilityName'] . '</td>';
                 echo '<td style="text-align:center" width="6%">'. $row['totalQty'] . '</td>';
            echo '</tr>';
            }
            }               
        Database::disconnect();

    ?>
</div>

index page-this is where the result will show

table1

那么如何根据“dueDate”将这6个表合并到一个表中呢?

0 个答案:

没有答案