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条)

报告相同问题?

悬赏问题

  • ¥15 扫描枪扫条形码出现问题
  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?