将下拉菜单列添加到php表

时间:2020-01-22 21:13:50

标签: php mysql selection

大家好,我有一个工作的简化php表,如下所示。

<!DOCTYPE html>
<html>
<head>
    <title>LifeSaver DB</title>
    <h1> LifeSaver Database </h1>
</head>
<body>
    <table>
        <tr>
            <th>Id</th>
            <th>Location</th>
            <th>Footage</th>
            <th>Notes</th>

        </tr>
        <?php
        $conn = mysqli_connect("localhost", "Kevin", "Pass", "LifeSaverDB"); 
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
            }

        $sql = "SELECT id, Location, Footage, Notes FROM LifeSaver1";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {

                //for href row
                $id = $row['id'];
                $Footage = ['Footage'];

                echo 
                "<tr>
                    <td>" . $row["id"]. "</td>

                    <td>" . $row["Location"] . "</td>
                    <td>" . $row["Notes"] . "</td>
                    <td> <a href='test.php'?id= . $id .'>" . $row['Footage'] . "</a> </td>

                </tr>";}

                //show table
                echo "</table>";
                } else { echo "0 results"; }
            $conn->close();

    ?>
    </table>
</body>
<style>

table, td, th {
  border: 1px solid black;
  margin: auto;
}

table {
  border-collapse: collapse;
color: #000;   <!--font colour -->
font-family: monospace;
font-size: 18px;
text-align: center;}

th {
background-color: #337AFF;
color: white;
font-weight: bold; }

tr:nth-child(odd) {background-color: #add8e6}


</style>
</html>

我想添加一个下拉菜单列,现在我从较大的脚本中分离出了这个小元素,以为可以完成这项工作。

<html>

<TABLE>


   <tr>  
    <td>
       <select>        
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="mercedes">Mercedes</option>
            <option value="audi">Audi</option>
       </select>
    </td>        
</tr>
</TABLE>

</html> 

所以我想我可以将其夹在其中,如下所示。但是它说服务器无法处理请求。 我认为while循环不喜欢它只是一个独立的列表,而不是来自phpmyadmin的行请求这一事实,但我可能是错的。请帮助

<!DOCTYPE html>
<html>
<head>
    <title>LifeSaver DB</title>
    <h1> LifeSaver Database </h1>
</head>
<body>
    <table>
        <tr>
            <th>Id</th>
            <th>Drop</th>
            <th>Location</th>
            <th>Footage</th>
            <th>Notes</th>          
        </tr>
        <?php
        $conn = mysqli_connect("localhost", "Kev", "Pass", "LifeSaverDB"); 
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
            }

        $sql = "SELECT id, Location, Footage, Notes FROM LifeSaver1";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {

                //for href row
                $id = $row['id'];
                $Footage = ['Footage'];

                echo 
                "<tr>
                    <td>" . $row["id"]. "</td>
                    <td>
                       <select>        
                            <option value="volvo">Volvo</option>
                            <option value="saab">Saab</option>
                            <option value="mercedes">Mercedes</option>
                            <option value="audi">Audi</option>
                       </select>
                    </td> 
                    <td>" . $row["Location"] . "</td>
                    <td>" . $row["Notes"] . "</td>
                    <td> <a href='test.php'?id= . $id .'>" . $row['Footage'] . "</a> </td>

                </tr>";}

                //show table
                echo "</table>";
                } else { echo "0 results"; }
            $conn->close();

    ?>
    </table>
</body>
<style>

table, td, th {
  border: 1px solid black;
  margin: auto;
}

table {
  border-collapse: collapse;
color: #000;   <!--font colour -->
font-family: monospace;
font-size: 18px;
text-align: center;}

th {
background-color: #337AFF;
color: white;
font-weight: bold; }

tr:nth-child(odd) {background-color: #add8e6}


</style>
</html>

0 个答案:

没有答案