使用 select 框获取数据库

Getting database fetched with select box

我正在使用 bootstrap 库测试我在 php 中的技能,但我已经走投无路了。

我有两个表,studentscountries

我有一个 select 框,我可以在其中获取国家(以及相关 ID),我想以表格形式查看来自该国家/地区的学生。

实际上,我得到了表格,得到了select但是我找不到如何一起互动。

请帮帮我。谢谢

我的代码php

<?php

//Access to BDD
include 'database.php';
?>
<html>

<Head> 
<title>List of students</title> 
<script src="bootstrap/js/bootstrap.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
</Head>

<body>

<!-- formulaire de recherche -->
<form class="panel-group form-horizontal" method="get" action="home.php" role="form">
<div class="panel panel-default">
    <div class="panel-body">
        <div class="panel-header">
            <h4>Search</h4>
        </div>
        <div class="col-sm-3">
            <!-- dropdown countries -->

        <select class="form-control" id="select" name="country"> 
            <option value="">country</option>
            <?php
                    $sel_country = "SELECT * FROM countries";
                    $run_country = mysqli_query($conn,$sel_country);
                    while ($rows= mysqli_fetch_assoc($run_country)){
                    echo '<option value='.$rows['id'].'>'.$rows['brand_name'].'</option>';
                    }
            ?>
        </select>
        <br/>
        <br/>



            <button type="submit" class="btn btn-default" id="searchbtn" name="submit">Go</button>
        </div>
    </div>  
</div>
</form>

<?php 

//SQL listing all the students.

$sql = "SELECT * FROM student ORDER by student_id"; //CHOIX NON PLUS!!!
$run_sql = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_assoc($run_sql)){

        echo '<div class="container">   
                <table class="table table-hover">
                    <tr>
                        <td><h2><a class="btn btn-info" href="detail.php?vo_id='.$rows['student_id'].'">'.$rows ['name'].'</a></h2></td>
                    </tr>
                    <tr>
                        <td>'.$rows ['surname'].'</td>
                    </tr>
                    <tr>
                        <td>'.$rows ['age'].'</td>
                    </tr>
                    <tr>
                        <td>'.$rows ['country'].'</td>
                    </tr>
                </table>    
            </div>
                <br>';
}?>

更新现有代码中的以下代码: 假设所有代码都在同一页上 (home.php)

  if(isset($_GET[country]))
    {
    $sql = "SELECT * FROM student WHERE country_id =". $_GET["country"]." ORDER by student_id"; //CHOIX NON PLUS!!!
    $run_sql = mysqli_query($conn, $sql);
    while ($rows = mysqli_fetch_assoc($run_sql)){

            echo '<div class="container">   
                    <table class="table table-hover">
                        <tr>
                            <td><h2><a class="btn btn-info" href="detail.php?vo_id='.$rows['student_id'].'">'.$rows ['name'].'</a></h2></td>
                        </tr>
                        <tr>
                            <td>'.$rows ['surname'].'</td>
                        </tr>
                        <tr>
                            <td>'.$rows ['age'].'</td>
                        </tr>
                        <tr>
                            <td>'.$rows ['country'].'</td>
                        </tr>
                    </table>    
                </div>
                    <br>';
}