new_forward
Профессор
- Регистрация
- 5 Май 2008
- Сообщения
- 673
- Реакции
- 44
- Автор темы
- #11
Вот моя функция которая делает запрос и сортирует :
Подправить ее бы...
Код:
function GetList($fcv_array, $sortBy='', $ascending=true, $limit='')
{
$sqlLimit = ($limit != '' && $sortBy == ''?"LIMIT $limit":'');
if (sizeof($fcv_array) > 0)
{
$questionList = Array();
$Database = new DatabaseConnection();
$this->pog_query = "select questionid from `question` where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$this->pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
{
$this->pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]) && $this->pog_attribute_type[$fcv_array[$i][0]][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]][0] != 'SET')
{
$this->pog_query .= "`".strtolower($fcv_array[$i][0])."` ".$fcv_array[$i][1]." '".($fcv_array[$i][2])."'";
}
else
{
$this->pog_query .= "`".strtolower($fcv_array[$i][0])."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
}
}
}
$this->pog_query .= " order by questionid DESC $sqlLimit";
$Database->Query($this->pog_query);
$thisObjectName = get_class($this);
for ($i=0; $i < $Database->Rows(); $i++)
{
$question = new $thisObjectName();
$question->Get($Database->Result($i, "questionid"));
$questionList[] = $question;
}
if ($sortBy != '')
{
$f = '';
$question = new question();
if (isset($question->pog_attribute_type[$sortBy]) && ($question->pog_attribute_type[$sortBy][0] == "NUMERIC" || $question->pog_attribute_type[$sortBy][0] == "SET"))
{
$f = 'return $question1->'.$sortBy.' > $question2->'.$sortBy.';';
}
else if (isset($question->pog_attribute_type[$sortBy]))
{
$f = 'return strcmp(strtolower($question1->'.$sortBy.'), strtolower($question2->'.$sortBy.'));';
}
usort($questionList, create_function('$question1, $question2', $f));
if (!$ascending)
{
$questionList = array_reverse($questionList);
}
if ($limit != '')
{
$limitParts = explode(',', $limit);
if (sizeof($limitParts) > 1)
{
return array_slice($questionList, $limitParts[0], $limitParts[1]);
}
else
{
return array_slice($questionList, 0, $limit);
}
}
}
return $questionList;
}
return null;
}
Подправить ее бы...