Categories
Mastering Development

PHP if/elseif statement not working as intended

I am trying to make an if/elseif statement work in php and everything seems to work just fine, besides if the "locid" is empty, or not present, i want to display a different query. Could someone help me figure out whats wrong with the code?

Basically, the if(empty($locid)) statement does not work. The page appears as blank.

This is the code:

if (isset($_GET['locid'])) {
    $locid = $_GET['locid'];
    if (empty($locid)) {
        $selectloc = "SELECT * FROM locations;";
    } elseif ($locid == 'all') {
        $selectloc = "SELECT * FROM locations;";
    } elseif ($locid == 'veterinary') {
        $selectloc = "SELECT * FROM locations WHERE location_cate='Veterinary';";
    } elseif ($locid == 'store') {
        $selectloc = "SELECT * FROM locations WHERE location_cate='Store';";
    } elseif ($locid == 'shelter') {
        $selectloc = "SELECT * FROM locations WHERE location_cate='Shelter';";
    } elseif ($locid == 'other') {
        $selectloc = "SELECT * FROM locations WHERE location_cate='Other';";
    } else {
        $selectloc = "SELECT * FROM locations;";
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *