vendredi 22 mars 2019

Mixing Conditional Types

I'm working on a dynamic function that generates a MySQL WHERE clause but apparently mixing different types of conditionals doesn't work. Unless there is a typo that I've missed, I don't see the problem here in this (so far untested) foreach loop can can anyone please advise? It uses both single line conditionals and more conventional if elseif statments using : and endif rather than { and }.

$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

Aucun commentaire:

Enregistrer un commentaire