我试图在表中添加一个下拉菜单框,其中包含从mysql获取的数据

时间:2015-06-14 13:54:22

标签: php mysql twitter-bootstrap

我正在使用notepad,xampp和mysql以及phpMyadmin创建一个足球预测网站。在预测页面上,我有一个页面显示了表格中的夹具。我希望使用能够使用一系列数字1-20的下拉菜单为每个相应的装置发布Home_SoreAway_Score

例如:

Fixture_ID|Home_Team|Home_Score|Away_Score|Away_Team|
      1   Man United <Dropdown> <Dropdown> Spurs

这可能吗?我是php编码的新手,非常感谢我得到的任何帮助!:)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<?php


$connection = mysql_connect('localhost', 'root', 'password'); //The Blank string is the password
mysql_select_db('mls');

$query = "SELECT * FROM fixtures"; //You don't need a ; like you do in SQL
$result = mysql_query($query);


        $columns = array();
        $resultset = array();

        # Set columns and results array
        while ($row = mysql_fetch_assoc($result)) {
            if (empty($columns)) {


                $columns = array_keys($row);
            }

            $resultset[] = $row;
        }


        # If records found
        if( count($resultset > 0 )) {
?>
            <table class="table table-bordered" >
                <thead>
                    <tr class='info';>
                        <?php foreach ($columns as $k => $column_name ) : ?>
                            <th> <?php echo $column_name;?> </th>

                        <?php endforeach; ?>
                    </tr>
                </thead>
                <tbody>

                    <?php

                        // output data of each row
                        foreach($resultset as $index => $row) {
                        $column_counter =0;

                    ?>
                        <tr class='success';>
                            <?php for ($i=0; $i < count($columns); $i++):?>


                                <td> <?php echo $row[$columns[$column_counter++]]; ?>   </td>
                            <?php endfor;?>


                        </tr>

                    <?php } ?>


                </tbody>
            </table>

    <?php }else{


    ?>


        <h4> echo Information Not Available </h4>
    <?php } 



?>



</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以在td代码

中添加类似内容
<select name="mySelect"> 
    <?php $result= mysql_query('SELECT * FROM fixtures'); ?> 
    <?php while($row= mysql_fetch_assoc($result)) { ?> 
        <option value="<?php echo $row['your_column_name'];?>"> 
            <?php echo $row['your_column_name']; ?> 
        </option> 
    <?php } ?> 
</select>