douxin1956 2017-09-04 11:42
浏览 63
已采纳

PHP:尝试使用组合框过滤表中的数据库信息[关闭]

So I am trying to sort information based the selected item in the combo box. I am familiar with parts of PHP but still learning.

I was able to fill the combo box with the 'Brand_Name' Column information from my DB.

This is my current output: image

It is not filtering though, it is just listing all items in the DB

See code below:

<?php
$hostname = "localhost";
$username = "root";
$password = "root";
$databaseName = "Clients";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$queryDropdown = "SELECT * FROM `Brands` WHERE 1";
$result = mysqli_query($connect, $queryDropdown);
$queryGrid = "SELECT * FROM `Brands` ";
$SearchResult = mysqli_query($connect, $queryGrid);
?>
<html>
<head>
    <title>PokerPass</title>
      <link rel="stylesheet" type="text/css" href="styles/Main.css">
      <link rel="stylesheet" type="text/css" href="styles/ComboBox.css">
      <link rel="stylesheet" type="text/css" href="styles/TableGrid.css">
</head>
<body >
    <div id="Container" class="Container">
        <div id="Header" class="Header">

        </div>
        <div id="Body" class="Body">
            <div name="start" id="Filter_Bar" class="Filter_Bar">
                <select class="soflow" id="soflow" Size="1">
                  <?php while($row1 = mysqli_fetch_array($result)):; ?>
                  <option><?php echo $row1[1]; ?></option>
                <?php endwhile; ?>
                </select>
                <button class="Submit" ><span><strong>Search<strong></span></button>
                <!--<input class="Submit" type="submit" name="search" value="Search </span>">-->
            </div>
            <div id="Data_Grid" class="Data_Grid">
                  <table>
                    <tr>
                      <th>Server ID</th>
                      <th>Client</th>
                      <th>Operator</th>
                      <th>Username</th>
                      <th>Password</th>
                    </tr>
                    <?php while ($row = mysqli_fetch_array($SearchResult)):; ?>
                    <tr>
                      <td><?php echo $row['ServerID']; ?></td>
                      <td><?php echo $row['Brand_Name']; ?></td>
                      <td><?php echo $row['Operator_Name']; ?></td>
                      <td><?php echo $row['Username']; ?></td>
                      <td><?php echo $row['Password']; ?></td>
                    </tr>
                    <?php endwhile; ?>
                  </table>
            </div>
        </div>
        <div id="Footer" class="Footer">

        </div>
    </div>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • dtu15253 2017-09-04 13:57
    关注

    In your HTML code, your select element has no name attribute, so you won't be able to pick up its value when the form is submitted. Additionally, your option elements have no value attribute so even if the form was submitted and the select had a name, the value would be empty. See this guide.

    Your select element isn't inside a form tag, which means that the page has no idea where to go when the button is pressed. You need a form that specifies the action (the URL you are going to) and the method (post/get). See this guide.

    Finally, if you want PHP to know what your query was, you need to get it from the GET or POST parameters. Once you have the variable, you can make your SQL query dynamic - but be careful not to introduce an SQL injection vulnerability - validate the user input carefully (for instance, only allowing numbers as values in your select list) and/or use parameterized queries.

    If you want the form to be submitted automatically when the dropdown list is changed, you can use a quick JS attribute to auto-submit the form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM