下拉选项查询sql返回重复 [英] Dropdown option query sql return repeated
本文介绍了下拉选项查询sql返回重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何停止重复查询下拉菜单,如下图所示?
How do i stop the query for my dropdown from repeating as in the picture below?
请选择CD价格:
<select name="CDPrice">
<option value="">
<?php
include 'database_conn.php';
if (!( is_object($conn) && ( get_class($conn) == 'mysqli' ))) {
die("DB connection failure.");
}
$rsCDprice = mysqli_query($conn, "SELECT nmc_cd.CDPrice FROM nmc_cd");
if (!$rsCDprice) {
die("No result from DB query."); //probably invalid SQL, table error, etc.
}
if ($rsCDprice->num_rows < 1) {
die("No rows returned from DB query."); //query runs OK, but nothing is found in DB to match.
}
while ($Catpriceresult = mysqli_fetch_array($rsCDprice)) {
echo "<option value='" . $Catpriceresult[0] . "'>" . $Catpriceresult[0] . "</option>";
}
?>
</select>
推荐答案
尝试执行以下代码.请选择CD价格:
Try to execute below code. Please select CD Price:
<select name="CDPrice">
<option value="">
<?php
include 'database_conn.php';
if (!( is_object($conn) && ( get_class($conn) == 'mysqli' ))) {
die("DB connection failure.");
}
$rsCDprice = mysqli_query($conn, "SELECT DISTINCT nmc_cd.CDPrice FROM nmc_cd");
if (!$rsCDprice) {
die("No result from DB query."); //probably invalid SQL, table error, etc.
}
if ($rsCDprice->num_rows < 1) {
die("No rows returned from DB query."); //query runs OK, but nothing is found in DB to match.
}
while ($Catpriceresult = mysqli_fetch_array($rsCDprice)) {
echo "<option value='" . $Catpriceresult[0] . "'>" . $Catpriceresult[0] . "</option>";
}
?>
</select>
这篇关于下拉选项查询sql返回重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文