SELECT COMPANY: -6ren">
gpt4 book ai didi

php - 从数据库值填充下拉列表

转载 作者:太空宇宙 更新时间:2023-11-04 11:17:42 25 4
gpt4 key购买 nike

如何使用数据库值填充此下拉框。虽然这个问题似乎是重复的,但我在网上尝试了很多其他问题,但他们没有用。谢谢。

<div class="control-group <?php echo !empty($companynameError)?'error':'';?>">
<label class="control-label">SELECT COMPANY:</label>
<div class="controls">
<select name="companyname" id="companyname" onChange="enabledropdown()" placeholder="Product Type" value="<?php echo !empty($companyname)?$companyname:'';?>">
<?php if (!empty($companynameError)): ?>
<span class="help-inline"><?php echo $companynameError;?></span>
<?php endif; ?>
<?php
$pdo = Database::connect();
$cdquery = "SELECT companyname FROM company WHERE username=" .mysql_real_escape_string($_SESSION['username']);
$cdresult=mysql_query($cdquery) or die ("Query to get data from company failed: ".mysql_error());
while ($cdrow=mysql_fetch_array($cdresult)) {
$cdTitle=$cdrow["companyname"];
echo "<option>
$cdTitle
</option>";
}
Database::disconnect();
?>
</select>
</div>
</div>

最佳答案

尝试

<?php

$pdo = Database::connect();
$cdquery = "SELECT companyname FROM company WHERE username='" . mysql_real_escape_string($_SESSION['username']) . "'";
$cdresult = mysql_query($cdquery) or die("Query to get data from company failed: " . mysql_error());
while ($cdrow = mysql_fetch_array($cdresult)) {
$cdTitle = $cdrow["companyname"];
echo "<option>" .
$cdTitle
. "</option>";
}
Database::disconnect();
?>

根据您的代码。

关于php - 从数据库值填充下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33067851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com