I am having a problem to how avoid duplicates in my query, my code is like this:
<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>
the code is ok, but users are repeatedly in option selection?
您必须更改查询。
SELECT * from `user` Join `appointment` ON ( user.user_id = appointment.user_id) where appointment.branch_id = $session_branchid
You could change the SQL part to:
$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);
If the users' data are equal then the SQL will only return one record.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.