Home > Enterprise >  Ascending order of fetched data
Ascending order of fetched data

Time:02-16

enter image description here

I am fetching count. My target is to display it in ASCENDING ORDER. i have tried to sort it using sort($match); but i have still failed to achieve my goal. Thank you. Any help will be appreciated

Controller:

function asdasdas(){
            $entry= $this->repo->entryfetch();
            
            
            
            $data='<table>
    <thead><tr><th>NO. </th></tr></thead>';
          
            
            foreach($entry as $entry){
                
                $match= $this->repo->matchfetch($entry->handlerID);
                
                $data.='<thead><tr><th><hr>'.$entry->handlerID.'&nbsp;'.$entry->entryName.'</th> ';
     
             
                
                foreach($match as $match){
                    
                    $diff = $match->weightM - $match->weightW;
                    
                    if($match->handlerIDM === $entry->handlerID){
                        $name=$match->handlertestW;
                        $count=$match->countM;
                    }else{
                        
                        $name=$match->handlerM;
                        $count=$match->countW;
                    }
                    
                    
                    
                    $data.='<tbody><tr><td>'.$count.'</td>';
               
                    $data.='<td></td></tr></tbody>';
    //             
                }
               
                
            }
            
            $data .='<table>';
          
            echo $data;
            

sort($match); // i have tried to sort it using this but it is not working. }

CodePudding user response:

You can loop the array from the last index to 0

function asdasdas()
{
    $entry = $this->repo->entryfetch();
    $data = '<table>
    <thead><tr><th>NO. </th></tr></thead>';

    for ($j = count($entry) - 1; $j >= 0; $j--) {
        $match = $this->repo->matchfetch($entry[$j]->handlerID);
        $data .= '<thead><tr><th><hr>' . $entry[$j]->handlerID . '&nbsp;' . $entry[$j]->entryName . '</th> ';

        for ($i = count($match) - 1; $i >= 0; $i--) {
            $diff = $match[$i]->weightM - $match[$i]->weightW;
            if ($match[$i]->handlerIDM === $entry[$j]->handlerID) {
                $name = $match[$i]->handlertestW;
                $count = $match[$i]->countM;
            } else {
                $name = $match[$i]->handlerM;
                $count = $match[$i]->countW;
            }
            $data .= '<tbody><tr><td>' . $count . '</td>';
            $data .= '<td></td></tr></tbody>';
        }
    }
    $data .= '<table>';
    echo $data;
}

CodePudding user response:

Context is not much clear. Do you need to sort $match before for loop or while inside the forloop. Can you explain a bit if haven't got the solution.

  • Related