[eluser]Samus[/eluser]
[quote author="isran_85" date="1334054809"]i have function for sorting on my page:
model :
function sorting_data($table,$idx,$sort){
$this->db->select('0,1,2,3,4,5,6');
$this->db->order_by($idx,$sort);
$this->db->from($table);
$sql= $this->db->get();
return $sql->result_array();
}
function sort_data($sort_by,$username){
switch($sort_by){
case 'bonus':
$idx =0; $sort ="asc";
$cl_data=$this->Model_Statement->sorting_data($username,$idx,$sort);
break;
case 'profit':
$idx =1; $sort ="asc";
$cl_data=$this->Model_Statement->sorting_data($username,$idx,$sort);
break;
controller:
$sort_by = $this->input->post('sorting');
$cl_data = $this->Model_Directions->sort_closed_data($sort_by,$username);
but the result like this
from biggest to smallest)
> 1000
> -3.48
> -2.32
> -2.19
> -2.06
> -1.7
> -1.35
> -0.83
> -0.04
is that wrong (correct result is : 1000,-0.04,0.83,-1.35)
i use varchar type in my field,if i use float type result is correct,but change data type isn't allowed.
someone help me please !!
i've some solution here but how to create model in ci,i have php code:
<?
$moviedata = array(
array('movie'=>'Home Alone', 'genre'=>'Comedy', 'revenue'=>-285),
array('movie'=>'The Godfather', 'genre'=>'Drama', 'revenue'=>268),
array('movie'=>'Finding Nemo', 'genre'=>'Animation', 'revenue'=>866),
array('movie'=>'Star Wars', 'genre'=>'Sci-Fi', 'revenue'=>797),
array('movie'=>'Grease', 'genre'=>'Musical', 'revenue'=>387),
array('movie'=>'Ghostbusters', 'genre'=>'Comedy', 'revenue'=>238),
array('movie'=>'Titanic', 'genre'=>'Drama', 'revenue'=>-600)
);
$cols = array();
foreach($moviedata as $row) {
foreach($row as $key => $value) {
if( !isset($cols[$key]) )
$cols[$key] = array();
$cols[$key][] = $value;
}
}
$data = $cols;
array_multisort( $data['revenue'],SORT_ASC,$data['genre'],$data['movie']);
print_r($data);echo "<br>";
?>
this code will work for sorting but i can't to convert to codeigniter code.
here is my model code in codeigniter:
function sort_pips($base){
$i = 0;
$cols = array();
foreach ($base as $row){
foreach($row as $key => $value){
if( !isset($cols[$key]) )
$cols[$key] = array();
$cols[$key][] = $value;}
$data = $base[$i];
//$data = $cols;
array_multisort($data['13'],SORT_ASC,$data['1']);
$replacements = array(13 => $data13);
$basket[] = array_replace($data, $replacements);
$i++;
}
return $basket;
}
Please help me!!!!
[/quote]
try wrap your code in tags, it's hard to read in just plain text