[英]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.