mercredi 9 septembre 2015

PHP if statement building URLs

I have written the following IF statement

if ($mainCat && $subCat) {
    $url = "/subjects/".$mainCat->alias."/".$r->alias;
}

Which is working great. You can see a demo here: http://ift.tt/1UB72Kh

However I have expanded on it and want to include an elseif, if a variable is present but it's not working:

if ($subCat == 78) {
    $url = "/subjects/".$mainCat->alias."/".$subCat->alias."/".$r->alias;
}
elseif ($mainCat && $subCat) {
    $url = "/subjects/".$mainCat->alias."/".$r->alias;
}

The idea is, if a country ($subcat) is selected with an ID of '78' the URL will be rendered differently.

Aucun commentaire:

Enregistrer un commentaire