简体   繁体   English

如何使用php中的下拉菜单从数据库中获取数据并将其显示在标签上?

[英]How to fetch data from the database and display it to the labels using a dropdown in php?

I would like to display the retrieve data from the database into my input area using a dropdown list also generated from the database. 我想使用同样从数据库生成的下拉列表,将数据库中的检索数据显示到我的输入区域中。 The problem is when a run my code the customername input area is disappearing. 问题是当运行我的代码时,customername输入区域消失了。 Can you help me with these? 你能帮我这些吗?

Dropdown Note: My Dropdown is working I just included it. 下拉列表注意:我的下拉列表正在运行,我只添加了它。

<?php
           $connect = mysqli_connect("localhost", "root", "", "xls_db");  
         ?>
             <select name="customercode" id="customercode" class="form-control"> 
             <option value="" > -----------Customer Code----------- </option> 
         <?php
            $dd_res=mysql_query("Select DISTINCT customercode from cr18_cust_listing WHERE Status = 'Active' ");
            while($r=mysql_fetch_row($dd_res))
            { 
               echo "<option value='$r[0]'> $r[0] </option>";
            }
         ?>
            </select>

PHP to display text PHP显示文字

<?php
        $connect = mysqli_connect("localhost", "root", "", "xls_db");  
         if(isset($_POST["customercode"]))  
        {  
      if($_POST["customercode"] != '')  
      {  
           $sql = "SELECT * FROM cr18_cust_listing WHERE customercode = '".$_POST["customercode"]."'";  
      }  
      $result = mysqli_query($connect, $sql);  

     while($r = mysqli_fetch_array($result))  
      {  


      ?>
        <div class="form group has-feedback">
            <input class="form-control" type="text" name="accntname" required="required" placeholder="Customer Name" value="<?php echo $r['customername'] ?>"><span class="glyphicon glyphicon-user form-control-feedback"></span><br />
            </div>
<?php }
       }    ?>

Missing Customer Name input Area 缺少客户名称输入区

截图

尝试下面的代码您已关闭文本区域而未打开它。

<input class="form-control" name="accntname" required="required" placeholder="Customer Name" value="<?php echo $r['customername'] ?>"><span class="glyphicon glyphicon-user form-control-feedback"></span><br />

For Dropdown 对于下拉

<?php
$conn=new mysqli("localhost","root","","xls_db");
if($conn->connect_error)
{
     echo $conn->connect_error;
     die("sorry database connection failed");
}
         ?>
                <select name="customercode" id="customercode" class="form-control" required>
                <option value="" > -----------Customer Code----------- </option>
    <?php

$sql = "Select DISTINCT customercode from cr18_cust_listing WHERE Status = 'Active'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "<option value='";
        echo $row['customercode'];
        echo "'>";
        echo $row['customercode'];
        echo "</option>";
    }
}
    ?>

    </select>

thats it , this will work for sure 就是这样,这肯定可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PHP根据下拉列表中的选择从数据库中获取数据? - How to fetch data from database based on selection in the dropdown using PHP? 如何从数据库中获取数据并在PHP中显示? - How to fetch data from database and display it in PHP? 如何从数据库中获取数据并以html下拉列表显示? - How to fetch data from database and display in html dropdown? 从数据库中获取数据并显示在下拉列表中 - fetch data from database and display in dropdown list 我如何使用ajax从PHP中的一个表中显示的两个表的下拉列表中获取数据 - How can i fetch data at dropdown from two tables display in one table in PHP using ajax 使用PHP使用下拉列表显示数据库中的数据 - using PHP to display data from database using a dropdown list 如何将图像插入数据库并从数据库中获取并使用 PHP 显示? - How to insert images into the database and fetch it from the database and display using PHP? 使用php和ajax从数据库中获取数据并显示到文本框 - Fetch data from database and display to a textbox using php and ajax 使用PHP将数据从数据库显示到下拉列表中 - Display data into dropdown list from database using php 从数据库中获取数据并使用php将其显示在表中 - Fetch data from database and display it in table using php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM