dsfs64664 2017-09-04 18:40
浏览 42
已采纳

尝试在数据库中搜索时显示的重复选项

I'm using php, and trying to build a code that allows me to search through my sql database vendors' passwords The search is based on vendor name . And it is possible that one vendor has more than one password . it is working fine , but one problem , which is when I try to select the vendor name , it is showing more than one time if in the database it shows more than one time . So how can I manage not to display the vendor name more than one time in the search options ? This is the php code I'm using:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>

<form action="/cloudpass/searchvendors.php" id="searchv" "method="GET"><br/><br/>
<select name="query" form="searchv">
<?php

$conn = new mysqli('localhost', 'root', '', 'mysql')
or die ('Cannot connect to db');

$sql = mysqli_query($conn, "SELECT vendor_name FROM vendors");

while ($row = $sql->fetch_assoc()){

$vendor_name = $row['vendor_name'];
echo '<option value="'.$vendor_name.'">'. $row['vendor_name'] .'</option>';
}
?>
</select>

        <input type="submit" value="search" />
    </form>

</body>
</html>

And this is my problem

  • 写回答

1条回答 默认 最新

  • dpv50040 2017-09-04 18:42
    关注

    for avoid duplicated value simply use distinct clause

     SELECT distinct vendor_name FROM vendors
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?