[英]How to avoid repeat selection on select query option?
我在如何避免查询重复中遇到问题,我的代码如下:
<div class="control-group">
<label class="control-label" for="inputPassword">User:</label>
<div class="controls">
<select type="text" name="user_id" placeholder="User" >
<option><?php
$sql1=mysql_query("SELECT * from `user`,`appointment` where user.user_id = appointment.user_id and appointment.branch_id = $session_branchid")or die(mysql_error);
while($row = mysql_fetch_array($sql1)){
echo "<option value=".$row["user_id"].">" .$row["firstname"].' '.$row["lastname"]. "</option>";
}
?></option>
</select>
</div>
</div>
代码还可以,但用户反复选择选项?
您必须更改查询。
SELECT * from `user` Join `appointment` ON ( user.user_id = appointment.user_id) where appointment.branch_id = $session_branchid
您可以将SQL部分更改为:
$sql1 = mysql_query("SELECT DISTINCT * from `user`,`appointment` where user.user_id = appointment.user_id and appointment.branch_id = $session_branchid")or die(mysql_error);
如果用户的数据相等,则SQL将仅返回一条记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.