maloi59ru
Новичок
Дата регистрации:
20.03.2014 09:38:44
Сообщений: 8
private function select($table_name, $fields, $where = "", $order = "", $up = true, $limit = "" {
for ($i = 0; $i < count($fields); $i++) {
if ((strpos($fields[$i], "(" === false) && ($fields[$i] != "*") $fields[$i] = "`".$fields[$i]."`";
}
$fields = implode(",", $fields);
$table_name = $this->config->db_prefix.$table_name;
if (!$order) $order = "ORDER BY `id`";
else {
if ($order != "RAND()" {
$order = "ORDER BY `$order`";
if (!$up) $order .= " DESC";
}
else $order = "ORDER BY $order";
}
if ($limit) $limit = "LIMIT $limit";
if ($where) $query = "SELECT $fields FROM $table_name WHERE $where $order $limit";
else $query = "SELECT $fields FROM $table_name $order $limit";
$result_set = $this->query($query);
if (!$result_set) return false;
$i = 0;
while ($row = $result_set->fetch_assoc()) {
$data[$i] = $row;
$i++;
}
$result_set->close();
return $data;
}
и
public function getAll($table_name, $order, $up) {
return $this->select($table_name, array("*", "", $order, $up);
}
Все работает нормально, но я не знаю как дописать в select правило $order .= " ASC" и написать функцию с сортировкой например:
public function getAllAsc(???) {
return $this->select(???);
}