选项显示表中的值

时间:2015-03-19 09:40:05

标签: php html sql

我有:Selector.php

<!--Selector-->
<?php
    $render->makeSelector($database);
    $render->makeDetailTable($database);
?>

Render.php

<?php
class render {
    private $pdo;

function makeSelector($database){
    //Get name and id data from the db. In an assoc array
    $results = $database->Selector();
    echo "<form name='form' id='selector'>";
    echo "<select multiple='multiple'>";
    // Loop trough the results and make an option of every train_name
    foreach($results as $res){
                echo "<option>" . $res['train_name'] . "</option>";
        }   
    echo "</select>";
    echo "<br />" . "<td>" . "<input type='submit' name='Submit' value='Submit' tabindex='2' />" . "</td>";
    echo "</form>";
    }


function makeDetailTable($database){
    //Get all data from database, in an assoc array
    $results = $database->getAllAssoc();

    //Make table headers
    ?>
    <div id="train_select_table">
    <table>
        <tr>
            <th>Train name</th>
            <th>Tare weight</th>
            <th>Number of bogies</th>
            <th>Number of axles</th>
            <th>min Wheel diameter</th>
            <th>Max wheel diameter</th>
        </tr>
    <div id="loopRow">
        <?php      
            foreach($results as $res){
            //Loop trough results, generate a tablerow every time
        ?>
        <tr>        
            <?php echo "<td>" . $res['train_name'] . "</td>";
            echo "<td>" . $res['tare_weight'] . "</td>";
            echo "<td>" . $res['number_of_bogies'] . "</td>";
            echo "<td>" . $res['number_of_axles'] . "</td>";
            echo "<td>" . $res['wheel_diameter_min'] . "</td>"; 
            echo "<td>" . $res['wheel_diameter_max'] . "</td>";
            ?> 
        </tr>
    <?php 
        } 
    ?>
    </div>
    </table>
    </div>
    <?php
    }


}
?>

我在database.php中的函数

function selector() {
        $sql = "SELECT train_id, train_name FROM train_information";
        $sth = $this->pdo->prepare($sql);
        $sth->execute();
        return $sth->fetchAll();
    }

function getAllAssoc() {
        $sql = "SELECT * FROM train_information";
        $sth = $this->pdo->prepare($sql);
        $sth->execute();
        return $sth->fetchAll();
     }

现在,该页面显示了一个选择器(包含所有“train_name”值。这是有效的。 在那之下,我有一张桌子。但是现在,该表显示了train_information表中的所有内容。但这并不好,因为:

我只想显示客户选择的信息。所以你去了网站。桌子是空的。您从选择器中选择几列火车,然后按提交。按下提交时,我只想在表格中显示所选列车,而不是一切。

我该怎么做?

0 个答案:

没有答案