I’m trying to build up some functions to variably build up queries from arrays. And i need to know whether i’m actually doing it correctly. Right now i’m wondering if this function to build a variable “WHERE” is okay, or should be improved.
Any opinions / tips are appreciated.
private function buildWhereFromArray($var, $array, $count)
{
$where = '(';
for($i = 0; $i <= ($count - 1); $i++)
{
if(!is_numeric($array[$i]))
{
return false;
}
$where .= '('.$var.' = '.$array[$i].')';
if($i != ($typeCount - 1))
{
$where .= ' AND ';
}
}
$where .= ')';
return $where;
}
The variables should be obvious.
If you want to limit a resultset to, say,
fooisa,borc, you can use the mysqlIN()function.