Php - 如何从 mysql 中排除数据

标签 php mysql

如何从下面的列表菜单中排除一些国家?现在我的代码将列出数据库中的所有国家/地区名称。

示例 我想从列表菜单中排除阿尔巴尼亚国家。如何根据这些代码实现。

代码

    <?php $select_country=mysql_query("SELECT * FROM tbl_country ORDER BY country_name ASC")?>
    <select name="country"  onchange="return get_country(this.value);">
        <option value=""><?=SELECT_COUNTRY?></option>
        <? while($country=mysql_fetch_array($select_country)) {?>
           <option  <? if($_SESSION['getcountry']==$country['id']){ ?> selected="selected"<? }?> value="<?=$country['id']?>">
           <?=$country['country_name']?></option>
        <? } ?>
    </select>

数据库

id    country_name
1   Afghanistan
2   Aland Islands
3   Albania
4   Algeria
5   American Samoa
6   Andorra

最佳答案

从结果集中排除该行:

SELECT * FROM tbl_country WHERE country_name != "Albania" ORDER BY country_name ASC

或者你用 PHP 跳过它:

<?php
    while($country=mysql_fetch_array($select_country)) {
        if ($country['country_name'] == 'Albania') {
            continue;
        } ?>
    <option <?php if($_SESSION['getcountry']==$country['id']){ ?> selected="selected"<? }?> value="<?=$country['id']?>"><?=$country['country_name']?></option>
<?php } ?>

关于Php - 如何从 mysql 中排除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1248641/

相关文章:

mysql - 删除行时出现问题

php - 从文本框提交 MySQL 查询?

mysql - 如何从 MySQL 中选择按创建日期和名称排序的标签,但删除重复的名称?

php - 媒体查询在 WordPress 中不起作用

php - MySQL从多个表中选择

mysql - 为什么 mongoDB 的 Select 时间比 Fetch 时间少?

javascript - 按钮不调用脚本 - onclick 方法

php - 使用 Angular ngRepeat 显示 php 选择的 JSON 数据

php - 如何在jeditable中发送多个变量?

php - Redis sub/pub 一次多个发布