PCHomepage
Programmer
I've done this countless times but for some reason it is giving grief this time. I am trying to create a dynamic NOT LIKE clause for use in a function that creates a select box. It is working but it is repeating the query over and ever even though there are no other loops within the function and the function itself is not being called inside any loop. This started out as a simple [bold]for[/bold] and was also tried as [bold]foreach[/bold], now [bold]while[/bold], all with identical results. What could be wrong?
In case it helps, here is the function itself:
Code:
if ($NotLikeSelect):
$values = $NotLikeSelect;
while(list(, $value) = each($values)):
$LikeWhere .= "AND ". $Field." NOT LIKE '".$value."%' ";
endwhile;
$Where = " WHERE ".$Field ." IS NOT NULL ".$LikeWhere;
endif;
In case it helps, here is the function itself:
Code:
function SelectBox($Field, $Key, $Table, $Multiple, $LikeSelect, $NotLikeSelect, $Default = '', $mysqli) {
global $Selected;
global $AddRow;
if ($NotLikeSelect):
$values = $NotLikeSelect;
reset($values);
while(list(, $value) = each($values)):
$LikeWhere .= "AND ". $Field." NOT LIKE '".$value."%' ";
endwhile;
$Where = " WHERE ".$Field ." IS NOT NULL ".$LikeWhere;
elseif ($LikeSelect):
$values = $LikeSelect;
reset($values);
while(list(, $value) = each($values)):
$LikeWhere .= "AND ". $Field." LIKE '".$value."%' ";
endwhile;
$Where = " WHERE ".$Field ." IS NOT NULL ".$LikeWhere;
endif;
if ($Multiple == '1'):
$Multiple = " multiple=\"multiple\"";
$Selector = "[]";
$NumRows = " size=\"2\"";
$AddRow = "<option value=\"\"></option>\n";
elseif ($Multiple >= '2'):
$Multiple = " multiple=\"multiple\"";
$Selector = "[]";
$NumRows = " size=\"$Multiple\"";
$AddRow = "<option value=\"\"></option>\n";
else:
$Multiple = "";
$Selector = "";
$AddRow = "";
$NumRows = "";
endif;
$Output = "<select name=\"".str_replace(" ", "", $Default).$Selector."\" Class=\"SelectBox\"".$Multiple.$NumRows." onchange='this.form.submit()'>\n";
$Output .= "<option value=\"\">".$Default."</option>\n";
$Output .= "$AddRow";
$Query = "Select DISTINCT ".$Field .", ID FROM ".$Table.$Where." GROUP BY ".$Field." ORDER BY ".$Field;
if ($result = $mysqli->query($Query)):
$i = 0;
while ($row = $result->fetch_row()):
if (isset($_POST[$Field]) && $row[$Key] == $_POST[$Field] && $_POST[$Field] != ""):
$Selected = " SELECTED";
else:
$Selected = "";
endif;
$Output .= "<option value=\"".$row[$Key]."\"".$Selected.">".substr(basename($row[0], '.csv'),0,50)."</option>\n";
$i++;
endwhile;
$result->close();
endif;
$Output .= "</select>";
$Output .= $row[$Key];
echo $Query;
}