Q: Mixing Conditional Types I'm attempting to replace a chunk of code that has hard-coded field names with one that gets the field names dynamically from the query and have it mostly working but only up to a point, then I get an error. This is the code that I am trying to replace with a foreach loop of field names which creates the WHERE clause:
if (strlen($Where) == 0 ) $Where .= " WHERE (";
    $Where .= "(" . $StorageArea . ")";
if (strlen($Where) > 0 ) $Where .= " AND ";
    $Where .= " (" . $StorageArea . ")";
 if (strlen($Location))
    $Where .= " OR (". $Location .")";
if (strlen($Size))
    $Where .= " OR (". $Size .")";
if (strlen($Winery))
    $Where .= " OR (". $Winery .")";
if (strlen($Brand))
    $Where .= " OR (". $Brand .")";
if (strlen($Appellation))
    $Where .= " OR (". $Appellation .")";
if (strlen($ReleaseYear))
    $Where .= " OR (". $ReleaseYear .")";
if (strlen($Varietal))
    $Where .= " OR (". $Varietal .")";
if (strlen($Status))
    $Where .= " OR (". $Status .")";
if (strlen($CountryName))
    $Where .= " OR (". $CountryName .")";
$Where .= " ) ";

Unless there is a typo that I've missed, I don't see the problem here in this (so far untested) foreach loop so can can anyone please advise? TO keep it simply and to avoid lots of if else it uses both single line conditionals and more conventional if elseif statements using : and endif rather than { and }. Is there some limitation of this type of conditional? I had always thought that they were directly interchangeable but apparently not. 
$i = 1;
$len = count(array_keys($queryField));
foreach (array_keys($queryField) as $row) :
    $i++:
    if ($row === 'ID') continue;
    if ($i == 1) :
        if (strlen($Where) == 1) $Where .= " WHERE (";
        $Where .= " (" . $$row . ") ";
        if (strlen($Where) > 1) $Where .= " AND ";
    elseif ($i > 1 && $i != $len) :
        if (strlen($$row)) $Where .= " OR (". $$row .")";
    elseif ($i == $len) :
        if (strlen($$row)) $Where .= " OR (". $$row .")";
        $Where .= ")";
    endif;
endforeach;

The error is Parse error: syntax error, unexpected ':' which it is giving on the elseif ($i > 1 && $i != $len) : line. I'm not sure yet if this will even do what I want but I can't try it until I get it working.
$queryField is a query with results as below and the function grabs the field names from it
Array
(
    [ID] => 3
    [StorageArea] => CAB-1
    [Size] => 
    [Winery] => Name
    [Brand] => Fanciful Name
    [Appellation] => 
    [ReleaseYear] => 2008
    [Varietal] => Cuvée
    [Status] => Library
    [CountryName] => 
)

Thanks to the comments and answer received to get the above working, I realized it does not do what I had expected so I rethought it and came up with something completely different that does work. Since it's not exactly an answer, I am posting it here as a quasi-answer and the fun part was in trying to know how many times the inner foreach was looped. There are other sections to this too for All Keywords or Exact Phrase but this bit is very similar to those so no need to post all of them. $Where is being declared earlier in the function from which this code was extracted so it's not shown here.
For my basic question about mixing conditional types, apparently mixing if and endif with single line conditionals isn't possible and that { and } are recommended for non-HTML-based programming but I really wanted to keep everything the same so for this version, all are single-line conditionals within the foreach loops so no errors.
$keywords = explode(" ", trim($keyword));
// Get number of passes for inner loop
// Subtract one because ID column is not being used
$len = ((count(array_keys($queryField))-1) * count($keywords));
$i = - (count($keywords)); // Subtract number of keywords
if (strlen($keyword)) :
    // Any Keywords
    foreach ($keywords as $keyword) :
        $keyword = str_replace("'", "''", trim($keyword));
        foreach (array_keys($queryField) as $column) :
            $i++;
            if ($column === 'ID') continue;
            if (strlen($Where) == 0) $Where .= " WHERE (";
            if ($i != $len) $Where .= "(`$column` LIKE '%" . $keyword . "%') OR ";
            if ($i == $len) $Where .= "(`$column` LIKE '%" . $keyword . "%') ";
        endforeach;
    endforeach;
endif;


A: There are a few typos there but most of all for this to work you'd have to break up your code like so:
<?php
$i = 1;
$len = count(array_keys($queryField));
?>
<?php
foreach (array_keys($queryField) as $row) :
    $i++;
    if ($row === 'ID') continue;
?>
<?php
    if ($i == 1) :
        if (strlen($Where) == 1) $Where .= " WHERE (";
        $Where .= " (" . $$row . ") ";
        if (strlen($Where) > 1) $Where .= " AND ";
?>
<?php
    elseif ($i > 1 && $i != $len) :
        if (strlen($$row)) $Where .= " OR (". $$row .")";
?>
<?php
    elseif ($i == $len) :
        if (strlen($$row)) $Where .= " OR (". $$row .")";
        $Where .= ")";
?>
<?php
    endif;
endforeach;
?>

Unfortunately it's not possible to mix conditional statements as shown in your code. 
If this code isn't supposed to be used in an HTML template i suggest sticking to {} brackets:
$i = 1;
$len = count(array_keys($queryField));
foreach (array_keys($queryField) as $row) {
    $i++;
    if ($row === 'ID') continue;
    if ($i == 1) {
        if (strlen($Where) == 1) $Where .= " WHERE (";
        $Where .= " (" . $$row . ") ";
        if (strlen($Where) > 1) $Where .= " AND ";
    }
    elseif ($i > 1 && $i != $len)
        if (strlen($$row)) $Where .= " OR (". $$row .")";
    elseif ($i == $len) {
        if (strlen($$row)) $Where .= " OR (". $$row .")";
        $Where .= ")";
    }
}

