没有视图重复工作

时间:2014-06-14 09:03:16

标签: php mysql

如何防止表格中的重复记录:

<select name="web_site">
     <?php
        $query = $db->query("SELECT * FROM `work`");
        while ($row = mysql_fetch_array($query)) {
            print '<option value="'.$row['id'].'">'.$row['title'].'</option>';
        }
    ?>
</select>

2 个答案:

答案 0 :(得分:0)

$query = $db->query("SELECT * FROM `work` group by title");

答案 1 :(得分:0)

<select name="web_site">
     <?php
        $query = $db->query("SELECT DISTINCT title FROM `work`");
        while ($row = mysql_fetch_array($query)) {
            print '<option value="'.$row['id'].'">'.$row['title'].'</option>';
        }
    ?>
</select>