• <bdo id='u5EyU'></bdo><ul id='u5EyU'></ul>
    <legend id='u5EyU'><style id='u5EyU'><dir id='u5EyU'><q id='u5EyU'></q></dir></style></legend>

    1. <small id='u5EyU'></small><noframes id='u5EyU'>

        <i id='u5EyU'><tr id='u5EyU'><dt id='u5EyU'><q id='u5EyU'><span id='u5EyU'><b id='u5EyU'><form id='u5EyU'><ins id='u5EyU'></ins><ul id='u5EyU'></ul><sub id='u5EyU'></sub></form><legend id='u5EyU'></legend><bdo id='u5EyU'><pre id='u5EyU'><center id='u5EyU'></center></pre></bdo></b><th id='u5EyU'></th></span></q></dt></tr></i><div id='u5EyU'><tfoot id='u5EyU'></tfoot><dl id='u5EyU'><fieldset id='u5EyU'></fieldset></dl></div>

      1. <tfoot id='u5EyU'></tfoot>

        PHP- 从数据库中获取并存储在下拉菜单 html 中

        时间:2023-10-03

        <small id='BYxwR'></small><noframes id='BYxwR'>

          <legend id='BYxwR'><style id='BYxwR'><dir id='BYxwR'><q id='BYxwR'></q></dir></style></legend>
            <bdo id='BYxwR'></bdo><ul id='BYxwR'></ul>

            <i id='BYxwR'><tr id='BYxwR'><dt id='BYxwR'><q id='BYxwR'><span id='BYxwR'><b id='BYxwR'><form id='BYxwR'><ins id='BYxwR'></ins><ul id='BYxwR'></ul><sub id='BYxwR'></sub></form><legend id='BYxwR'></legend><bdo id='BYxwR'><pre id='BYxwR'><center id='BYxwR'></center></pre></bdo></b><th id='BYxwR'></th></span></q></dt></tr></i><div id='BYxwR'><tfoot id='BYxwR'></tfoot><dl id='BYxwR'><fieldset id='BYxwR'></fieldset></dl></div>
              <tbody id='BYxwR'></tbody>
          • <tfoot id='BYxwR'></tfoot>
                • 本文介绍了PHP- 从数据库中获取并存储在下拉菜单 html 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我似乎无法获得以下代码来制作包含来自 mysql 数据库的数据的下拉菜单.包含('connect.php');"连接到 mysql 数据库,我知道它在不同的页面上工作.有什么建议?

                  I can't seem to get the following code to make a dropdown menu that contains data from a mysql database. The "include('connect.php');" connects to the mysql database and I know it works on separate pages. Any suggestions?

                  以下是完整代码.列出客户

                  Below is the entire code. listCustomer

                   <BODY>
                   <H1>Find Customer's Albums Page</H1>
                   From a dropdown list of customers, a user should be able to pick a customer and see a list of     albums (all fields in the CD table) purchased by that customer.
                   <HR>
                   <FORM ACTION="listCustomer.php" METHOD="POST"/>
                   Customer:
                   <select name="mydropdownCust">
                   <option value="101">101</option>
                   <option value="102">102</option>
                   <option value="103">103</option>
                   <option value="104">104</option>
                   <option value="105">105</option>
                   <option value="106">106</option>
                   <option value="107">107</option>
                   <option value="108">108</option>
                   <option value="109">109</option>
                   <option value="110">110</option>
                   </select>
                   <BR>
                  
                   <?php
                   include('connect.php');
                  
                   $query = "SELECT Cnum, CName FROM Customer";
                   $result = mysql_query ($query);
                   echo "<select name=dropdown value=''>Dropdown</option>";
                   while($r = mysql_fetch_array($result))
                   {
                   echo "<option value=$r["Cnum"]>$r["CName"]</option>"; 
                   }
                   echo "</select>";
                   ?>
                  
                   <BR>
                   <INPUT TYPE="SUBMIT" Value="Submit"/>
                   </FORM>
                  
                   <FORM ACTION="listMenu.html" METHOD="POST"/>
                   <INPUT TYPE="SUBMIT" Value="Main Menu"/>
                   </FORM>
                   </BODY>
                   </HTML>
                  

                  推荐答案

                  <?php
                  include('connect.php');
                  
                  $query = "SELECT Cnum, CName FROM Customer";
                  $result = mysql_query ($query);
                  echo "<select name='dropdown' value=''><option>Dropdown</option>";
                  while($r = mysql_fetch_array($result)) {
                    echo "<option value=".$r['Cnum'].">".$r['CName']."</option>"; 
                  }
                  echo "</select>";
                  ?>
                  

                  从表面上看,您缺少一个开始选项标签,所以它只是输出Dropdown"作为一行文本.

                  From the looks of things, you're missing an opening option tag, so it's just outputting "Dropdown" as a line of text.

                  为了完全透明,因为我没有connect.php,我不得不添加我自己的数据库连接.我的整个页面看起来如此:

                  Just to be completely transparent, because I did not have connect.php, I had to add my own DB connections. My whole page looked thusly:

                  <?
                  //Adding to display errors.
                  error_reporting(E_ALL);
                  ini_set('display_errors', '1');
                  ?>
                  <HTML>
                  <HEAD>
                  </HEAD>
                  <BODY>
                   <H1>Find Customer's Albums Page</H1>
                   From a dropdown list of customers, a user should be able to pick a customer and see a list of albums (all fields in the CD table) purchased by that customer.
                   <HR>
                   <FORM ACTION="listCustomer.php" METHOD="POST"/>
                   Customer:
                   <select name="mydropdownCust">
                   <option value="101">101</option>
                   <option value="102">102</option>
                   <option value="103">103</option>
                   <option value="104">104</option>
                   <option value="105">105</option>
                   <option value="106">106</option>
                   <option value="107">107</option>
                   <option value="108">108</option>
                   <option value="109">109</option>
                   <option value="110">110</option>
                   </select>
                   <BR />
                   <?php
                    // BEGIN ADDED CONNECTION HACKY GARBAGE
                    $con=mysql_connect("localhost","root","root");
                    // Check connection
                    if (mysqli_connect_errno($con)) {
                      echo "Failed to connect to MySQL: " . mysqli_connect_error();
                    }
                    $selected = mysql_select_db("sample",$con) 
                      or die("Could not select examples");
                    // END ADDED CONNECTION HACKY GARBAGE
                  
                    $query = "SELECT Cnum, CName FROM Customer";
                    $result = mysql_query ($query);
                    echo "<select name='dropdown' value=''><option>Dropdown</option>";
                    while($r = mysql_fetch_array($result)) {
                      echo "<option value=".$r['Cnum'].">".$r['CName']."</option>"; 
                    }
                    echo "</select>";
                   ?>
                  
                   <BR />
                   <INPUT TYPE="SUBMIT" Value="Submit"/>
                   </FORM>
                  
                  <FORM ACTION="listMenu.html" METHOD="POST"/>
                  <INPUT TYPE="SUBMIT" Value="Main Menu"/>
                  </FORM>
                  </BODY>
                  </HTML>
                  

                  这篇关于PHP- 从数据库中获取并存储在下拉菜单 html 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:CodeIgniter select_value in form_dropdown 下一篇:PHP MySQL 下拉框填充选定值

                  相关文章

                  最新文章

                    <tfoot id='sKR1a'></tfoot>

                    <i id='sKR1a'><tr id='sKR1a'><dt id='sKR1a'><q id='sKR1a'><span id='sKR1a'><b id='sKR1a'><form id='sKR1a'><ins id='sKR1a'></ins><ul id='sKR1a'></ul><sub id='sKR1a'></sub></form><legend id='sKR1a'></legend><bdo id='sKR1a'><pre id='sKR1a'><center id='sKR1a'></center></pre></bdo></b><th id='sKR1a'></th></span></q></dt></tr></i><div id='sKR1a'><tfoot id='sKR1a'></tfoot><dl id='sKR1a'><fieldset id='sKR1a'></fieldset></dl></div>
                    • <bdo id='sKR1a'></bdo><ul id='sKR1a'></ul>
                    <legend id='sKR1a'><style id='sKR1a'><dir id='sKR1a'><q id='sKR1a'></q></dir></style></legend>

                    <small id='sKR1a'></small><noframes id='sKR1a'>