Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php - How to exclude data from mysql

Tags:

php

mysql

How to exclude some of countries from List Menu at below? Now my code will list all of country name from database.

Example I want to exclude Albania country from the List Menu. How to implement it according to these code.

Code

    <?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>

Mysql

id    country_name
1   Afghanistan
2   Aland Islands
3   Albania
4   Algeria
5   American Samoa
6   Andorra
like image 506
wow Avatar asked Sep 11 '25 02:09

wow


2 Answers

Either exclude that row from the result set:

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

Or you skip it with 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 } ?>
like image 130
Gumbo Avatar answered Sep 13 '25 15:09

Gumbo


If I have understood your question:

 mysql_query("SELECT * FROM tbl_country WHERE country_name <> 'Algeria' ORDER BY country_name ASC")
like image 37
astropanic Avatar answered Sep 13 '25 16:09

astropanic