在 sql 表上选择函数

我问了一个关于这个问题的问题 - 在表格中添加一个下拉列表。每个人都专注于<td> href我在表格中的一个,它实际上是有效的,尽管我被告知是过时的语法。


所以我想好吧,他们比我知道的多……所以起初我尝试了那些不起作用的建议。然后我想好了为什么不干脆把这东西拉出来呢?也许它会导致其余代码出现问题。


所以我完全删除了它,所以绝对不是那个 -<td><select>导致问题的正是这个元素。然而,同样的元素可以自己工作......我的其余代码没有它也能工作???


我在这方面的经验是老伙计们,请只是一个小小的帮助就意味着很多


<!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", "Me", "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>

                       <select>        

                            <option value="volvo">Volvo</option>

                            <option value="saab">Saab</option>

                            <option value="mercedes">Mercedes</option>

                            <option value="audi">Audi</option>

                       </select>

                    </td> 


                </tr>";}


                //show table

                echo "</table>";

                } else { echo "0 results"; }

            $conn->close();


    ?>

    </table>

</body>

<style>


table, td, th {

  border: 1px solid black;

  margin: auto;

}



DIEA
浏览 135回答 2
2回答

LEATH

这是引号。这是无效的 PHP,并且会(应该?)给出 PHP 错误(如果display_errors在 php.ini 文件中为 On):echo"<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["id"]. "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["Location"] . "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["Notes"] . "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<select>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="volvo">Volvo</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="saab">Saab</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="mercedes">Mercedes</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="audi">Audi</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>";IMO您希望双引号中的值属性,因此建议将所有其他引号更改为单引号/勾号(')

精慕HU

迪诺,你是个传奇。我坐了几个小时……叹息。任何人,它现在已经排序,对于任何几个月后跟随我的人。这就是解决方案。我现在可能会按照 Dino 的建议调整其他报价,我很高兴它正在工作echo"<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["id"]. "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["Location"] . "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>" . $row["Notes"] . "</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<select>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value='volvo'>Volvo</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value='saab'>Saab</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value='mercedes'>Mercedes</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value='audi'>Audi</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>";}
打开App,查看更多内容
随时随地看视频慕课网APP