简体   繁体   English

如何在while循环中只允许每个名称之一?

[英]How do you only allow one of each name in a while loop?

I am not sure how to word this question, but I have a bunch of codes and I am trying to make an options list so that the user can select which one they want. 我不确定如何表达这个问题,但是我有很多代码,我试图制作一个选项列表,以便用户可以选择他们想要的代码。 I am fetching the codes from a query $acquery = mysql_query("SELECT * FROM schedules") and I put it into a while loop. 我从查询$acquery = mysql_query("SELECT * FROM schedules")获取代码,并将其放入while循环中。

PHP: PHP:

<?php
while($ac = mysql_fetch_assoc($acquery))
{
$sel = '';
echo '<option value="'.$ac[code].'" '.$sel.'>'.$ac[fullname].'</option>';
}
?>   

Since the schedule query has multiples of the same code, it lists the same thing repeatedly. 由于计划查询具有相同代码的倍数,因此它将重复列出相同的内容。 How can I make sure that it lists a unique code ($ac[code] and $ac[fullname] every time? 我如何确保它每次都列出一个唯一的代码($ ac [code]和$ ac [fullname]?

If I understand the question correctly, you can do this by fixing the SQL query to do what you want: 如果我正确理解了该问题,则可以通过修复SQL查询以执行所需的操作来做到这一点:

SELECT DISTINCT code, fullname
FROM schedules;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM